Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何处理UITableViewCell变得不可见?_Ios_Uitableview - Fatal编程技术网

Ios 如何处理UITableViewCell变得不可见?

Ios 如何处理UITableViewCell变得不可见?,ios,uitableview,Ios,Uitableview,当UITableViewCell变得不可见时,我需要释放一些资源prepareforeuse消息,但我需要另一条消息。。。我有UITableViewCell子类,可以覆盖一些消息 这正是我需要的: 但这是iOS6+唯一的解决方案。我需要iOS4.3+解决方案。当单元格隐藏时,它将从UITableView中删除。因此,您可以在UITableViewCell派生类方法willMoveToSuperview中重写: - (void)willMoveToSuperview:(UIView *)newSu

UITableViewCell
变得不可见时,我需要释放一些资源<当需要重用
UITableViewCell
时,会发送code>prepareforeuse消息,但我需要另一条消息。。。我有
UITableViewCell
子类,可以覆盖一些消息


这正是我需要的:


但这是iOS6+唯一的解决方案。我需要iOS4.3+解决方案。

当单元格隐藏时,它将从
UITableView
中删除。因此,您可以在
UITableViewCell
派生类方法
willMoveToSuperview
中重写:

- (void)willMoveToSuperview:(UIView *)newSuperview
{
    [super willMoveToSuperview:newSuperview];
    NSLog(@"%p willMoveToSuperview: %p", self, newSuperview);
    if(newSuperview == nil) {
        // release some resources here
    }
}

这正是我需要的:


但这是iOS6+唯一的解决方案。我需要iOS4.3+解决方案。

UITableView
继承自
UIScrollView

因此,一种可能的方法应该是实现
scrollViewDidScroll
方法,并在那里检查哪个
UITableViewCell
可见

这也应有助于:
添加一个else解决了我的问题。我重置了对单元格所做的任何更改

if (! self.cell) {
self.cell = [[LanguageCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
self.cell.accessoryType = UITableViewCellAccessoryNone;
}
else
{ 
self.cell.checkImage.image = NO;

}

你确定你需要这个吗?如果您使用的是单元重用,您的单元将被回收,您将在那里释放您的资源。谢谢!!!!!!!我也需要这个。刚刚检查过。。。只有当单元格第一次可见时,才会调用此方法。所以我总共只看到6个调用,这是我的重用池的大小。
newSuperview
从未变成
nil
Hm。。。我刚刚在模拟器中检查过,它似乎在工作。我在方法中添加了
NSLog
,它证明了这个概念。我有一个想法。如果要填充整个屏幕的单元格太多,则可能不会调用方法
willMoveToSuperview
,因为单元格可以在同一时刻重用,而无需从表中删除。尝试在
prepareforeuse
too.Hm.中释放资源。。我已经仔细检查过了<每次调用code>willMoveToSuperview。