Objective-C:Table Cell消失后是否有任何事件? [英] Objective-C: Is there any event when a Table Cell goes away?

查看:100
本文介绍了Objective-C:Table Cell消失后是否有任何事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当表格单元格消失时(滚动表格时)是否有任何可以覆盖的消息?

Is there any message I can override called when a Table Cell goes away (on scrolling the table)?

我认为它应该类似于dealoc。

I think it should be something like dealoc.

我问这个因为我有以下情况:
我有一个包含许多单元格(100+)的表格,每个单元格都包含一个ImageView。为了加载图像(从URL)我正在使用NSOperationQueue / NSInvocationOperation。当用户在图像完全加载之前滚动表格时会出现问题:因为我正在重复使用单元格,图像显示在错误的单元格中。

I'm asking this because I have below situation: I have a table with many cells (100+) and each of this cell contains a ImageView. For loading the image (from a URL) I'm using NSOperationQueue/NSInvocationOperation. The problem appears when user is scrolling the table before the image is completely loaded: because I'm reusing the cells the image is displayed in wrong cell.

为了避免这种情况我当单元格消失时,我正在考虑使用NSOperationQueue对象的cancelAllOperations。

To avoid this I'm thinking to use "cancelAllOperations" of NSOperationQueue object when the cell goes away.

注意:如果我在prepareForReuse上调用此消息,我已尝试但无法正常工作。

Note: I've tried but is not working if I call this message on "prepareForReuse".

推荐答案

如果有,它将在 UITableViewDelegate 中类引用: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITableViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UITableViewDelegate

If there were, it would be in the UITableViewDelegate class reference: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITableViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UITableViewDelegate

他们唯一拥有的是 willDisplayCell 让你做最后一个在单元格出现之前进行快速调整。当它消失时它们没有任何东西,但是你可能会想到这一点,因为对于给定的单元格高度,屏幕上一次只有一定数量的单元格。

The only thing they have is willDisplayCell which lets you do last minute adjustments BEFORE the cell appears. They don't have anything for when it disappears, but you could probably figure that out since there are only a certain number of cells on the screen at a time for a given cell height.

因此,如果出现一个并且例如单元格高度为80(在纵向模式下,因此屏幕高度为480px),那么你可以说距离一个6个单元是即将消失(6个细胞* 80个像素= 480)。还有一些其他的事情需要考虑,比如滚动的方式,但是你会得到一般的想法。

So if one is appearing and for a cell height of 80 for instance (in portrait mode so 480px screen height), then you can say that the one 6 cells away is about to disappear (6 cells * 80 pixels = 480). There are a couple other things to consider like which way you are scrolling, but you get the general idea.

示例代码:您还应该通过Apple的示例代码 http://developer.apple.com/iphone/library/samplecode/LazyTableImages/Introduction/Intro.html

Example Code: You should also look at lazy table loading via Apple's sample code http://developer.apple.com/iphone/library/samplecode/LazyTableImages/Introduction/Intro.html

这篇关于Objective-C:Table Cell消失后是否有任何事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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