문제

I'm using a UITableViewController subclass with clearsSelectionOnViewWillAppear set to YES (the default value).

How do I make changes to a deselected cell when it is automatically deselected on viewWillAppear:?

도움이 되었습니까?

해결책

tableView:didDeselectRowAtIndexPath: is not called when a cell is deselected automatically on viewWillAppear: in a UITableViewController subclass.

Use the following code to make changes to the deselected in this case:

- (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];
}

In general, if you use deselectRowAtIndexPath:animated:, tableView:didDeselectRowAtIndexPath: will not be called.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top