UITableView doesn't keep row selected upon return

后端 未结 7 1006
独厮守ぢ
独厮守ぢ 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

    NSIndexPath *_selectedIndex ;
    

    use the above global variable to store in selected in the table view delegate method

        - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     _selectedIndex = [self.tableView indexPathForSelectedRow];
    }
    

    and in the following delegate of UINavigationController delegate method

    - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
    {
    [self.tableView selectRowAtIndexPath:_selectedIndex animated:NO scrollPosition:UITableViewScrollPositionNone];
    
    }
    

提交回复
热议问题