I have a UISplitViewController with a UITableView on the left and a custom view as the detail view.
When the UISplitViewController is loaded, I would like the first element in the TableView to be selected and viewed in the detail view. Currently I’m trying this in the TableView viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
[self tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
}
This almost works, except that the current row is not highlighted as when it is selected by the user. Is there a better way to do this?
You shouldn’t call
didSelectRowAtIndexPath:. The method you were intending isselectRowAtIndexPath:animated:scrollPosition:You can consider using a separate method as the default way to display something in your detail view. For example
- (void)displayObject:(NSObject *)objectToDisplay. This can be what you call in your didSelectRowAtIndexPath, but by moving the actual logic outside of that method, you will be able to call in other places, such as viewDidLoad or viewWillAppear. There you can also figure out what object it is you want to display (if you are dealing with an array that will be simple), and display it as such.