How to add an overlay to view the selected values in UIPickerView? - iphone

I have created a UIPickerView and I want to add an overlay view to show the user what he has selected. I don't know how to add it. Is there any property for that?
For example when we are selecting a date some overlay view will be there in the middle of UIPickerView, How should I get that ?
like: http://www.inexika.com/blog/Customizing-UIPickerView-UIDatePicker

In the UIPickerView , define
Add
pickerView.showsSelectionIndicator = YES;
and use the following method :-
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
}
Now in this add a UIView which you can call here, or just allocate it here itself adding what you want to addSubView in the UIView. Hope this much information is sufficient otherwise please tell . Thanks :)

Related

UIPickerView multi selection on ios7

I need a picker view witch i can select multi values, like the "select input" in HTML :
In ios6, i did it with a custom view created in the UIPickerViewDelegate (pickerView:viewForRow:forComponent:reusingView:) and a UIButton in each row, but since ios7, the custom view don't received the touch event.
Is it possible to do it in ios7 ?
DrDisc has confirmed that it is not possible to handle a touch event directly from a row view since ios7.
But it is possible to :
add a Tap Gesture to the UIPickerView
retrive the selected view
call a method to check / uncheck the row
int row = [self.pickerView selectedRowInComponent:0];
UIView *rowView = [self.pickerView viewForRow:row forComponent:0];
if([rowView isKindOfClass:[YouCustomView class]])
{
[(YouCustomView*)rowView toggleCheck];
[self.pickerView reloadAllComponents];
}
I think it is more natural than a button to check/uncheck, but we lost the ability to select an other row with a tap on it.
As far as I know, this is not possible. One option is to utilize UIPickerView's delegate method:
- (void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
You could store the selection in an array and change the text passed through from the data source to some sort of selection text ("x Selection 1").
Alternatively, you could have a 'select item' button that would add the currently displayed value to the selected array.
When the user clicks a button you can then look through the selected array for those that were selected.
These may not be the best methods, they're just my initial thoughts on it.

iPhone: How can I make a UITextField invisible but still clickable?

What I'm trying to do:
In a simple UITableView, I've got a form with both text and dates/times that can be edited. I'm using UITextFields in the date/time cells too, so that the inputView property can be used to display a datePicker over the keyboard.
What the problem is:
The problem with this is that these UITextFields are really just dummy fields that show a datePicker when selected. When they're selected, they show this annoying blue cursor that blinks - but these are just dummy text fields, and I don't want them to become visible at all.
If I set alpha = 0 or hidden = YES, then the textField no longer is clickable.
Any ideas of a way around this - or, a different solution to my initial problem? Thanks
I finally figured out a way around it. By hiding the UITextView, no touches are detected. However if I overlay a custom UIButton (which can be invisible) then I can activate the UITextField when the button is touched via
[myTextField becomeFirstResponder];
and then the datePicker will replace the keyboard just like it should.
I would use a UILabel with a UItapGestureRecognizer to know when the user taps on the label.
The text field control should only be used when actual text input is necessary.
Tell me if you need more help with the gesture recognizer, they are very easy to use and save you a lot of trouble.
To use the text field's "inputView" property, overlay your textfield on top of a label. Then simply hide and show the textfield from the textFieldDid* methods, but show the actual display value in the label.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
....
[cell.contentView addSubview:myLabel];
[cell.contentView addSubview:myTextField];
....
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
if (textField == self.myTextField) {
[textField setHidden:YES];
}
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
if (textField == self.myTextField) {
[textField setHidden:NO];
}
}
- (void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
self.myLabel.text = #"Set value here";
}
See my answer here:
Disable blinking cursor in a UITextField
That will hide the cursor and give you the option of whether or not to display anything to the user.

Multiple UIPickerView with same data in one view. How can I get the content of both picker?

I have 2 UIPickerviews with the same data.
At the moment sb is clicking the save-Button I want to get the data from both PickerViews.
I already set a tag to both pickers and I also implemented the function:
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [symbolList objectAtIndex:row];
}
But I have no idea how to get on both datas at the same time.
For each picker view, use selectedRowInComponent: to find out the current selection. Use this to obtain the value from each picker view's data source, e.g:
NSString *pickerViewOneSelection = [symbolList objectAtIndex:[pickerViewOne selectedRowInComponent:0]];
NSString *pickerViewTwoSelection = [symbolList objectAtIndex:[pickerViewTwo selectedRowInComponent:0]];
I'm assuming that pickerViewOne and pickerViewTwo are pointers to your two picker views and you've already worked that part out. I have also assumed that your picker has only one component.
Set tag of pickerview.
first create IBOutlet of both picker view.
and set tag of picker view.
pickerview.tag == 10;

instantiate UIPicker with uitextfield string

I am trying to pass my UItextfield value over to a UIPicker that I have loading in a alertview I'm just not sure what functions are available to me to get the values back into the picker?
At a guess I should be doing something in my
- (NSInteger)pickerView:(UIPickerView*)pv numberOfRowsInComponent:(NSInteger)component
{
if (pv == pickerViewA) {
return 10;
}
else
return 16;
}
but looking at the developers notes their is not much info about the UIPickerViewDataSource other than returning number of rows...
any help would be greatly appreciated.
There are other data source and delegates as-
//for title of a row in a component
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
//for width of a componenet
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
//for row height of a component
-(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
//for number of components
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
for more info look at documentation -
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIPickerViewDelegate_Protocol/Reference/UIPickerViewDelegate.html
and
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIPickerView_Class/Reference/UIPickerView.html
You can use either one of the following two delegates to add data content to UIPickerView
– pickerView:titleForRow:forComponent:
– pickerView:viewForRow:forComponent:reusingView:
For the first one u can return any NSString object and you cannot customize anything like font size or color for that.
But if you use the second one you can add the data content as a view to UIPickerView which can be achieved using a UILabel and here you can customize the view as you require.
Hope this might help you
Happy coding !

UIPickerView realtime update on TextField

As soon as I scroll the PickerView (or) UIDatePicker, I need the value to get displayed on a TextField :
While Scrolling. Even when the picker is moving the text field should update itself. Is it possible ?
On the event that the Picker stops moving and comes to rest. Is there an event for the PickerView to come to rest so that I could update the textField (as soon as the pickerView comes to rest).
// I do not wish to use the TextFieldDidEndEditing
// I want the textField to update itself when the picker view comes to rest.
It would be helpful if anyone could solve 1) and 2)
(1) might not be possible. For (2), you can use the delegate method pickerView:didSelectRow:inComponent. Let me know if you need any help with this.
For UIPickerView
(1) Implement pickerView:titleForRow:forComponent,
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
// Every time the picker view is rotated, this method will be called to fetch the title.
NSInteger selectedRow = [pickerView selectedRowInComponent:0];
// Get selected row like above and process data and update text field.
[..] // Process the title
return the title.
}
(2) This is more obvious.
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
// You have the selected row, update the text field.
}
For the first question, this isn't possible with the default control however there is nothing to stop you writing your own and simulate the effect using touchesMoved etc...