1

I am working on an iPad app with a split view controller. I have a stock standard UITableView as the master view.

When the view opens, I would like it to select the first row in the list.

In ViewDidLoad I have:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];

[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];

When I run the app in the simulator it seems to select the first row (flashes) but then it is no longer selected. It is like something is clearing the selection after the ViewDidLoad method. I can touch and select rows just fine. Is there a property on the row or the prototype cell I need to set for this to work correctly?

Thanks in advance, Richard

Richard
  • 33
  • 3

1 Answers1

2

Try doing that in the viewDidAppear instead of viewDidLoad.

Edit:

Just one thing Richard, this works because when you actually enter in the viewDidAppear your UITableView has been fully reloaded. In case it hasn't, it wouldn't work. You can actually do something like this, which I recommend (check the comment from Eric Morand).

Rui Peres
  • 25,741
  • 9
  • 87
  • 137