Selected UItableViewCell staying blue when selecte

2019-01-21 03:46发布

When I push a view after a user has selected a UITableView row, the row gets a blue highlight, and then the new view appears. That's fine. But when I go 'back' the row is still highlighted in blue. Here's my didSelectRowAtIndexPath code.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    SettingsViewController *controller = [[SettingsViewController alloc] initWithNibName:@"SettingsView" bundle:nil];
    [[self navigationController] pushViewController:controller animated:YES];
    [controller release], controller = nil; 
}

What am I doing wrong?

7条回答
贪生不怕死
2楼-- · 2019-01-21 04:34

The default behaviour of UITableViewController deselects the row when the user returns from the detail view. The response given by Luke is fine, but I want to point out the reason for it:

1- If you have your UITableViewController like it was when you created it from scratch, you will have all the default behaviours.

2- If in the situation 1 you add a -viewWillAppear or -viewDidAppear, then you will be overwriting the standard behaviour. Them, if you want that the row deselects on return, you must say the super explicitly that you'd like it to deselect the row by himself as it always did! To achieve this, as Luke says, you must call [super viewWillAppear:animated] or [super viewDidAppear:animated] like this:

-(void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];

    // Here goes all of your stuff
}
查看更多
登录 后发表回答