如何使用prepareForReuse方法 [英] How to use prepareForReuse method

查看:155
本文介绍了如何使用prepareForReuse方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现这个方法名为 - (void)prepareForReuse 。我阅读文档但是我不明白如何使用它。

I found this method called - (void)prepareForReuse. I read the document but i don't understand how to use it.

当我滚动我的tableview时,它会卡住,或者滚动速度慢,我打算使用 prepareForReuse 。有人可以指点我一个好的教程或给我一些示例代码,以便我可以学习。

When i scroll my tableview, it gets stuck, or has slow scrolling and i intend to use prepareForReuse. Can someone please point me to a good tutorial or give me some sample code so i could learn.

抱歉,我没有任何代码来证明我的工作。

Sorry i don't have any code to demonstrate my working.

推荐答案

prepareForReuse 方法由一个单元格上的拥有表视图调用现在不需要。你应该在这里为你的自定义单元格进行小的清理,比如重置alpha值等,以便以后可以重复使用它。你不应该自己打电话,BTW。

The prepareForReuse method is called by the owning table view on a cell that is not needed right now. You are supposed to do minor cleanup here for your custom cell, like resetting alpha values and the like, so it can then later be reused. You shouldn't call it yourself, BTW.

如果你正在实现自定义表视图单元,你只需要关心它:你覆盖它来进行清理。

You only ever need to care about it if you're implementing custom table view cells: you overwrite it to do your cleanup.

你只是通过在 tableView中使用重用标识符来使用它:cellForIndexPath:

static NSString *CellIdentifier = @"Identifier";

cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                   reuseIdentifier:CellIdentifier];
    [cell autorelease];
    // Set up your cell
}

进一步改善您的表格视图性能,请参阅提高iPhone UITableView滚动性能的技巧?

To further improve your table view performance, see the question Tricks for improving iPhone UITableView scrolling performance?

这篇关于如何使用prepareForReuse方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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