MJeffryes
MJeffryes

Reputation: 458

Make UITableView selection before view appears

I'm building a detail view for a UITableView. The detail view contains a UITableView which has two rows, and I want the first one to be selected when the detail view is opened. I have tried to use the method [selectRowAtIndexPath:animated:scrollPosition] in [viewWillAppear]:

- (void) viewWillAppear:(BOOL)animated {  
    [[self tableView] selectRowAtIndexPath:[NSIndexPath indexPathForRow:kStartDateRow inSection:kSection]  
                                  animated:NO  
                            scrollPosition:UITableViewScrollPositionNone];  
}

However, the selection is not affected by this, and using it in [viewDidAppear] means the selection changes once the view has moved into place. How can I make the selection before the detail view appears on screen?

You can see an example of the behaviour I want in the Settings app. Go to General > Date & Time > Set Date & Time.

Upvotes: 3

Views: 1155

Answers (1)

user121301
user121301

Reputation:

You don't mention any error but try doing [[self tableView] reloadData] before the selectRowAtIndexPath line.

Upvotes: 3

Related Questions