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).
I can not find a good spot to call selectRowAtIndexPath:animated:scrollPosition: to initially select a
Share
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, andviewDidUnload.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.