iphone UIPickerView select row - iphone

I have my view that contains the UIPickerView...
I tried to make this code:
[self.picker selectRow:rowSelected inComponent:0 animated:true];
to select the row with index rowSelected, but this doesn't work...
I need to put this in viewdidload??

You do not call this method yourself. It is called by the system when a user selects a row in the pickerview. You should override the implementation of that method to do whatever you wish should happen when the user selects that row in that component.

Related

Data Pass to UIPickerView inside of UITableViewCell

I have UITableView and there is a picker view inside every cell. User can change value of every picker separately.
I need to know that which cell's pickerView is changed. For example, when user move a picker I will know that, this is cell 3.
Is there any way to do that? It's not necessary to get instant changed values. We can store it on array than send when Go button clicked that is not related with tableview.
I would suggest to store an array of pointers to your picker views. So index 0 of your array would point to the picker view of table row 0, etcetera. Then, make sure your view controller is the delegate of all picker views. Implement the pickerView:didSelectRow:inComponent: method declared by the UIPickerViewDelegate protocol. That method has an instance of UIPickerView as parameter: that's the one which value was changed. To obtain the row of that picker view, you can send your array the indexOfObject: method.
Create a subclass of a UITableViewCell. That subclass should get a reference to whatever you want to update, and then it can simply create (or IBOutlet link) to the picker and be a delegate of the picker.
So Cell should have:
- (void) passStuff:(NSMutableDictionary *)datamodel key:(NSString *)key values:(NSArray *)values {
_privateWeakRefDataModel = datamodel;
_privateCopyKey = key;
_privateValues = values;
[picker reloadData];
}
#pragma mark - Picker Delegate Code here
This way the cells will handle updating your data model directly. Keeps your code much cleaner.

iphone Table View Cell For Row not being called when Rows For Section is returning > 0

Using table views in a view controller that is being used as sub views to another controller. They are displaying fine when first created, etc. Selections are working fine, etc.
But when trying to change the display items in the table, the datasource array is being changed and a reload is done on the main thread. The Rows in Section is being called properly with the correct size of the array being returned, etc. BUT cell for row is not being called.
Here is the sub view setup...
[self addChildViewController : SQLTableNames];
[self.view addSubview : SQLTableNames.view];
[SQLTableNames didMoveToParentViewController : self];
Where SQLTableNames is a ViewController with tableview(s) in them
have tried everything, delayed reload, reload on main, etc. Delayed from the main view controller, delayed in the sub view controller, etc.
It's seems like the return from rows in section is simply being ignored.......
Have tried set need display, and Reload Rows at Index Paths. None of these will call the Cell for Row to repaint the table.
All the delegates are fine. It display's once fine and then can't change the table display.
If you called [self.tableView beginUpdates] before your inserts, ensure that you call
[self.tableView endUpdates];
after.

When is cellForRowAtIndexPath called?

I have a tableview in my app...The contents of this list view are displayed based on ext API dynamic search...
e.g. If I type "G" in searchbar it will display GA, GB, GC1, GC2, GC3,..
if I now change to GC, it will only display GC1, GC2, GC3..
I am storing the items in an array..
My question is how do I ensure that what the user is typing and seeing as search results are synchronized..I mean if he clicks on GC1 in list view, he should see GC1's detail and not other's..
Also when is cellForRowAtIndexPath called so that I can update the array each time user types in searchbar?
-cellForRowAtIndexPath: is sent by the table anytime it wants a cell to display, such as when the table is redrawn, or when a new cell is needed because the user scrolled a bit.
You can force the table to update its contents by calling [table reloadData], if 'table' is a pointer to your table.
You should be updating your array of filtered items in the filterContentForSearchText: scope: method. There is another method, searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString that will be called when the user types in the search bar. If you return YES from this method, then the table will be reloaded, which causes cellForRowAtIndexPath: to be called.

iphone UIPicker default position

Is there a way to set a default position for a UIPicker? I mean, if the user has the option of selecting any number from 1 to 100 in the UIPicker, can I set it to automatically start at 50?
You can use selectRow:inComponent:animated: like this:
[somePickerView selectRow:49 inComponent:0 animated:NO]; // Zero-indexed, so row 49 is the row that says 50
You can fire it in the viewDidLoad method for the UIViewController managing the view which contains the UIPickerView.
(It could also be that you can specify the default value in Interface Builder, but I'm not sure and I didn't check...)

iPhone-SDK:How to avoid Multiple Row Selection view?

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.