tableview插入刷新,用新数据重新加载uitableview导致闪烁

I added an infinite scrolling feature and realized that whenever I reload the uitableview, the view flickers..I am not sure how to fix the flickering at this point. Please help, thanks!

I did see a very similar question, but no solution to it. I tried the one the author posted, but it doesn't not work: "remove the tableview from parent view, reload data, put table view back into parent view" (UITableView reloadData - how to stop flicker)

Code:

[self.tableView reloadData];

解决方案

As you have guessed, flickering is caused by calling [self.tableView reloadData]; rapidly and repeatedly, especially on iOS 5.x devices. But you probably do not want to reload the entire table, you want to update just the view within the visible cells of the table.

Let's say you want to update each cell of a table to reflect the latest download % as a file is downloading. A method [downloading:totalRead:totalExpected:] gets called in my example, extremely rapidly as bytes are downloading.

This is what NOT to do... reload the table on every little update (in this example, the developer may rely on "cellForRowAtIndexPath" or "willDisplayCell" methods perform the updating of all the visible cells):

- (void)downloading:(PPFile *)file totalRead:(long long)read totalExpected:(long long)expected {

// Bad! Causes flickering when rapidly executed:

[self.tableView reloadData];

}

The following is a better solution. When a cell's view needs to be updated, find that cell by grabbing only the visible cells from the table, and then update that cell's view directly without reloading the table:

- (void)downloading:(PPFile *)file totalRead:(long long)read totalExpected:(long long)expected {

NSArray *cells = [self.tableView visibleCells];

for(MYCellView *cell in cells) {

if(cell.fileReference == file) {

// Update your cell's view here.

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值