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

前端 未结 6 1325
有刺的猬
有刺的猬 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:40

    I had the same question, and this is how I did it:

    In your tableViewController, add this in this function

    (UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    {    
        if(indexPath.row == 'the row you want to select')
        {
            [tableView 
                selectRowAtIndexPath:indexPath 
                animated:TRUE 
                scrollPosition:UITableViewScrollPositionNone
            ];
    
            [[tableView delegate] 
                tableView:tableView 
                didSelectRowAtIndexPath:indexPath
            ];
    
        }
    
    }
    

提交回复
热议问题