views:

250

answers:

4

I can not find a good spot to call selectRowAtIndexPath:animated:scrollPosition: to INITIALLY select a row in UITableView. Table data have not been loaded when the table view controller is initialized, so I can't do selection immediate after the initialization of my UITableViewController(Over bound exception would occur otherwise).

+1  A: 

try and overload viewWillAppear:aimated or viewDidAppear:animated make sure to call super as well.

make sure to call selectRowAtIndexPath:indexPath animated:NO as well, it will select without the time delay.

Jessedc
I've tried these already. But unfortunately, I need manually add UITableView as subview to another view so the view controller's viewWillAppear:aimated or viewDidAppear:animated would not be called. Besides, selecting every time view appears is more than "initial selection", and an extra flag is needed to determine whether this appearance is the first one.
an0
A: 

i've got this exact problem. solutions?

tom
A: 

You need to use viewWillAppear: to set the state of a view before it appears, every time it appears, even if the view has already been displayed previously. Any non-visible view in a UITabViewController or UINavigationViewController can be unloaded at any time, so you cannot count on a non-visble view to retain its state.

Or, for finer control, implement loadView, viewDidLoad, and viewDidUnload.

If you are maintaining your own hierarchy of view controllers you will have to manually forward the viewWillAppear, viewWillDisappear, etc., messages to your sub-view controllers.

Darren
A: 

you can set any cell selected in cellforrowatindexpath method of uitableview.By using cell.selected=YES;

Rahul Vyas