UITableView: selected cell after switching views

I use the UINavController along with some UITableViews to display some kind of granularity for some data (for example, as a contact application). Works good. The only problem I encountered is when I select a cell in the first view of the table, it is highlighted, then the view switches to the next level, and then, if I return to the first level, the cell is still highlighted. So how can I reset highlight when switching?

+3
source share
2 answers

In the controller, to present the table, do:

-(void) viewWillAppear:(BOOL)inAnimated {
    NSIndexPath *selected = [self.table indexPathForSelectedRow];
    if ( selected ) [self.table deselectRowAtIndexPath:selected animated:NO];
}

tableView:didSelectRowAtIndexPath:, .

+7

- .

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
+5

Source: https://habr.com/ru/post/1744206/


All Articles