How to unselect a UITableViewCell after you have done some action using didSelectRowAtIndexPath?

后端 未结 2 613
臣服心动
臣服心动 2021-02-02 10:48

Currently I do some work inside the didSelectRowAtIndexPath delegate and noticed that my row is still \"selected\" after I come back to the view controller later.

How ca

相关标签:
2条回答
  • 2021-02-02 11:23
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    0 讨论(0)
  • 2021-02-02 11:23

    Typically, you want to deselect the row when the view controller appears again:

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

    That's what UITableViewController does implicitly, and animating the deselection process after the view controller appears again is a helpful hint to the user as to which cell they selected previously.

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