UITableView doesn't keep row selected upon return

后端 未结 7 1007
独厮守ぢ
独厮守ぢ 2020-12-17 21:05

i have several table views in my app. I am familiar with the usual behaviour of tables, that when you select a row and progress to a pushed view, it turnes blue, then when y

7条回答
  •  盖世英雄少女心
    2020-12-17 21:28

    apparently viewWillAppear: of the class UITableView does deselect all cells, even without reloading the cells. The trick described worked for me:

    code from my UITablViewController:

    - (void)viewWillAppear:(BOOL)animated
    {
        NSIndexPath *selectedIndex = [self.tableView indexPathForSelectedRow];
    
        [super viewWillAppear:animated];
    
        //Re select cell
        [self.tableView selectRowAtIndexPath:selectedIndex animated:NO scrollPosition:UITableViewScrollPositionNone];
    };
    

提交回复
热议问题