保持选定的单元格处于重载状态reTableRowsAtIndexPaths UITableView [英] Keep selected cell on heavily reloadRowsAtIndexPaths UITableView

查看:62
本文介绍了保持选定的单元格处于重载状态reTableRowsAtIndexPaths UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在其中一个视图中,有一个UITableView会经常更新。
使用 reloadRowsAtIndexPaths以经典方式跟踪更改。

In one of the views there is a UITableView which is getting updated rather often. Tracking the changes are done in a classic way using "reloadRowsAtIndexPaths"

-(void)refreshCells:(NSArray *)changedCells
{
    NSLog(@"refreshCells %i",[changedCells count]);
    [TableView beginUpdates];
    [TableView reloadRowsAtIndexPaths:changedCells withRowAnimation:UITableViewRowAnimationBottom];
    [TableView endUpdates];
}

问题:如何保存用户最后一次选择的单元格。

Question: How can I preserve the user's last selected Cell. the cell position may change after each update refreshCells?

推荐答案

您可以使用

NSIndexPath *selectedRow = [self.tableView indexPathForSelectedRow];

在重新加载之前,然后使用

before the reload and select it again with

if (selectedRow) {
    [self.tableView selectRowAtIndexPath:selectedRow animated:NO scrollPosition:UITableViewScrollPositionNone];
}

重新加载后。除非您调用 insertRowsAtIndexPaths: deleteRowsAtIndexPaths:。否则,单元格位置不会改变。

after the reload. The cell position does not change unless you call insertRowsAtIndexPaths: or deleteRowsAtIndexPaths:.

这篇关于保持选定的单元格处于重载状态reTableRowsAtIndexPaths UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆