iPhone UITableView cells stay selected

前端 未结 7 1246
[愿得一人]
[愿得一人] 2020-12-28 11:50

in my UITableView sometimes cells stay selected after touching. Because it happens only occasionally, I\'m not able to reproduce the problem.

Any hints? Maybe it has

7条回答
  •  抹茶落季
    2020-12-28 12:51

    I can't tell you why you're seeing the issue, but here are some suggestions for fixing it:

    According to the Apple HIG, the selection should not disappear until returning from the view controller just pushed onto the stack. If your controller is just a UITableViewController, it should deselect automatically upon returning to the view. If not, add

    - (void) viewWillAppear:(BOOL)animated {
        [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:animated];
        [super viewWillAppear:animated];
    }
    

    somewhere in the view controller.

    If there are any rows that, when clicked, do not go to another view, and don't in fact do anything when selected, they shouldn't be selectable, so you can override that in

    - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
    

    and return nil in the cases that the row should not be selected.

提交回复
热议问题