I am working on a project where I want to have a picker view with 3 columns.
In the first column I want the user to select a letter.
Once the letter is selected I want the second column to update with a list of last names that start with that letter. When a last name is selected I want the third column to update with a list of first names who have the selected last name.
Can this even be done? Help!?
Get the letter that they selected using this pickerview delegate method:
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
You could load the next picker at this point but it would be better to populate the next picker when the done button on each picker is selected:
This is a nice SO post that describes how to use picker views very well: Dismissing UIPickerView with Done button on UIToolBar
Related
I have an application where I have a pickerview. In that picker I am displaying values from 1 to 100. When I select a value in picker say 2 that value is displayed in a textfield. I want that if my textfield contains value say 5 that value particular value should get displayed in my picker.
Now problem is when in textfield 5 is displayed and I go to pickerview it shows by default every time 1 selected irrespective of the value in the texfield. I want the value which is present in the textfield should get displayed on the pickerview also.
Use below code it will help you
[picker selectRow:[yourTxtObj.text intValue]-1 inComponent:0 animated:YES];
[yourPickerViewName selectRow:[textfield.text intValue] inComponent:yourComponent animated:YES]
This will work. It is used for select a row in picker.
I have set a picker view appearance on text field begin editing function and hide keyboard. Now problem is that when picker view appear then it show selection indicator on first value but that value not show in text field. I want that when user click on text filed then picker view appear and value from picker will show in text field where selection indicator place. How do that? Suppose i have four value in same order 0,1,2,3. Now when picker view appear then selection indicator is at on '0' value. But to get that value we have to scroll picker view and come back to '0' then it show that value in text field. Why it is occurs? And how get value automatically?
Thanks in advances...
Well, there is no connection between your picker view and the text field - you have to make it yourself.
There are two things to consider:
1) Your text field already contains a value, let's say "1". When you open the picker, you can set it to this value already with the function
[yourPicker selectRow:1 inComponent:0 animated:false]
, assuming your data array for the picker is [0, 1, 2, 3]. In your case, to make the text field contain the value 0, just call
[textField setText:#"0"]
2) When you are finished with the picker, it calls the delegate function
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
So you have to make your view implement the UIPickerViewDelegate protocol, implement the above delegate function in it and set the view as the picker view's delegate.
In the delegate function you can get the value the user picked (using row to access your data array values) and set this value in your textfield.
In my app, I ask a worker to choose a letter from the alphabet (for example A) and the alphabet will have some explications that will appear in a UIPickerView with 3 # rows.
I want my UIPickerView to be display contents based on the indicator that has been chosen by a worker.
How do I do this?
selection. in this case, it means showing the appropriate row in the middle
- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated;
scrolls the specified row to center.
please provide some code so That I can Get What exact issue is
How can i disable UIPickerView column?
I want to disable only one column of picker. Lets say i have picker with 3 column and i want to disable second column.
There are a couple options here.
1) Capture interaction with the second column and override it.
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;
This method can be implemented to simply go back to where it was before the selection. However, they will still be able to interact with the second column.
2) Simply remove the column from the picker.
I believe this is the best option. Have some boolean 'showSecondColumn'. Then, in:
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
you can simply check your little flag and return the appropriate number. UIPickerView has a method: reloadAllComponents
Good luck!
It seems there is no way to disable column. I solved(not best solution) like this:
get column as "image" (snapshot)
grayscale "image"
set "image view" user interaction enabled
add "image view" to picker as subview
If there is any better way it would be great.
I have a table and row contents(hard coded contents). when i choose one row and see the content and then come back to same table and try to choose another row, it doesn't deselect the first row selection(by default it shows Blue selection-UITableViewCellSelectionStyleBlue), instead both the rows are being in selected mode.
I was hoping, when we choose one row and then choose another row, by default it should unhighlight immediately the previous row selection.
Why and when should it happen?
I tried code 'cell.selectionStyle = UITableViewCellSelectionStyleNone;'
and tableView.allowsSelection=NO;
but no success, these are just not allowing completely from selection view.
I want when one row is selected and then the another is getting selected, the first row selection should be cleared and should show only the current row selection.
Any help please?
In your tableView:didSelectRowAtIndexPath: method or in the method you call when entering edit mode (the one containing [tableView setEditing:YES animated:YES];), add the following line:
[tableView deselectRowAtIndexPath:indexPath animated:YES];
before pushing a new controller.