删除行时平滑重新加载uitableview数据 [英] Smooth reload of uitableview data when rows are deleted

查看:166
本文介绍了删除行时平滑重新加载uitableview数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我滚动到屏幕底部时,我正在尝试重新加载它。我删除前几行并在底部添加更多行。 之前将新闻行添加到uitableview的数据源中,我调用 [tableview reloaddata] 方法。这是因为我希望tableview显示之前可见的行。

I am trying to reload a uitableview when it scrolls to the bottom of the screen. I delete the first few rows and add more rows to the bottom. Before the news rows are added to the uitableview's data source, i call the [tableview reloaddata] method. This is because i want the tableview to display the row which were previously visible on it.

它正确地重新加载数据但是tableview中突然出现了一个混蛋。它闪烁,无法提供良好的用户体验。所以我的问题是

It reloads the data correctly but there is a sudden jerk in the tableview. It flashes which doesn't give a nice user experience. So my question is


  1. 当顶部的几行被
    删除时,如何更新uitableview
    没有
    抽搐/闪烁效果?

  1. How to update the uitableview when few rows from the top are deleted without having the jerking/flashing effect?

当前可见行也应保留在刷新视图中。

The current visible row should be retained in the refreshed view also.

有什么想法吗?我正确更新数据源没有崩溃。

Any ideas? There are no crashes as i update the data source correctly.

TIA,

Praveen S

Praveen S

推荐答案

从tableView委托中的数据源中删除数据。

delete the data from the data source in tableView delegate.

 -(void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
    {


            NSString *key = [keys objectAtIndex:indexPath.section];
            NSMutableArray *nameSection =[names objectForKey:key];

            int itemID=item.ID;
            if ([nameSection count]==1) {
                [self.keys removeObjectsInArray:[NSArray arrayWithObject:key]];

                [tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade];
            }
            else {
                [nameSection removeObjectAtIndex:indexPath.row];
                [self.names setValue:nameSection forKey:key];

                [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] 
                                 withRowAnimation:UITableViewRowAnimationFade];
            }
        }

检查一下

这篇关于删除行时平滑重新加载uitableview数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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