Issue with deselectRowAtIndexPath in tableView

后端 未结 2 1172
一生所求
一生所求 2021-01-16 08:58

I have a cell with a few lines of text which changes colour when selected/highlighted. The problem is that as the new viewController is being pushed, the deselection animati

相关标签:
2条回答
  • 2021-01-16 09:54

    I think the general paradigm used with table views and pushing new VCs is that you deselect the table row in your viewWillAppear:animated method. Then as the VC is popped, they see which row had been used to navigate to that VC.

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    
        [self.myTableView deselectRowAtIndexPath:[myTableView indexPathForSelectedRow] animated:YES];
    
    }
    

    so remove deselectRow from your didSelectRowAtIndexPath method.

    0 讨论(0)
  • 2021-01-16 09:55

    If you're using a UITableViewController, you won't need to call deselectRowAtIndexPath:. This will be done for you automatically when your table view becomes visible again.

    If you're not using a UITableViewController because you have a more complicated interface, you would need to call deselectRowAtIndexPath: manually from the viewWillAppear:animated: method.

    0 讨论(0)
提交回复
热议问题