How to remember rows selected and maintain them after reload by default in UITableView?

前端 未结 6 1412
有刺的猬
有刺的猬 2020-12-14 01:09

How can I set a row selected by default? I want to select a row , take the number of selected row with indexpath.row and then reload the table and select the ro

6条回答
  •  鱼传尺愫
    2020-12-14 01:32

    NSIndexPath *indexPath = [tableView indexPathForSelectedRow];
    

    will give you the NSIndexPath for the current selected row. You can then do

    [tableView selectRowAtIndexPath:indexPath 
                           animated:NO 
                     scrollPosition:UITableViewScrollPositionMiddle];
    

    to select that row (and show it in the middle of the screen) later.

提交回复
热议问题