didDeselectRowAtIndexPath在viewWillAppear在UITableViewController中不调用
问题描述:
我使用的UITableViewController
子类clearsSelectionOnViewWillAppear
设置为YES
(默认值)。didDeselectRowAtIndexPath在viewWillAppear在UITableViewController中不调用
如何在取消选中的单元格在viewWillAppear:
上自动取消选中时对其进行更改?
答
tableView:didDeselectRowAtIndexPath:
未在UITableViewController
子类中的viewWillAppear:
上自动取消选中单元时调用。
使用下面的代码,以使在这种情况下取消更改:
- (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:
不会被调用。