我正在使用UITableViewController
子类,并将clearsSelectionOnViewWillAppear
设置为YES
(默认值)。
在viewWillAppear:
中自动取消选择的单元格时,如何对其进行更改?
最佳答案
在tableView:didDeselectRowAtIndexPath:
子类中的viewWillAppear:
上自动取消选择单元格时,不会调用UITableViewController
。
在这种情况下,使用以下代码对取消选择进行更改:
- (void) viewWillAppear:(BOOL)animated {
// HACK: Need to be called before super if the selection is cleared on viewWillAppear.
UITableViewCell* cell = [self.tableView cellForRowAtIndexPath:self.tableView.indexPathForSelectedRow];
// Change the cell
[super viewWillAppear:animated];
}
通常,如果使用
deselectRowAtIndexPath:animated:
,则不会调用tableView:didDeselectRowAtIndexPath:
。
关于iphone - 在UITableViewController中的viewWillAppear之后未调用didDeselectRowAtIndexPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11886354/