问题
In my SplitViewController, based on an action in the DetailViewController, I update the MasterViewController row using NSNotificationCenter essentially like this:
Keeping MasterViewController and DetailViewController in sync
The problem is, once an update to the row of the MasterViewController is done, the row is no longer selected. When I look at Apple's iPad apps using splitViews, like the Note application, a row is always selected. I want to do the same thing so everything stays in sync between my two tables. I can manually just setSelected:YES animated:NO
on the row since I have the indexPath of the tableView, but I still do see the blue highlight of the selected row flicker off before getting set on again. I don't want that.
MasterViewController:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
Scene *object = [[[DataManager sharedInstance] sceneArray] objectAtIndex:indexPath.row];
self.detailViewController.detailItem = object;
}
}
回答1:
This is the key - set this property on the UITableViewController:
self.clearsSelectionOnViewWillAppear = NO;
来源:https://stackoverflow.com/questions/10527504/keeping-mastertableview-row-selected-in-splitviewcontroller