简体   繁体   中英

How to handle UITableViewCell became not visible?

I need release some resources when UITableViewCell became out of visible rect. prepareForReuse message is sent when UITableViewCell needs to be reused, but I need another... I have UITableViewCell subclass, and can override some messages...

This is exactly what I need: tableView:didEndDisplayingCell:forRowAtIndexPath:

But this is iOS6+ only solution. I need iOS4.3+ solution.

When cell becomes hidden it is removed from the UITableView . So you can override in your UITableViewCell derived class method willMoveToSuperview :

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

This is exactly what I need: tableView:didEndDisplayingCell:forRowAtIndexPath:

But this is iOS6+ only solution. I need iOS4.3+ solution.

UITableView inherits from UIScrollView .

So one possible way should be to implement the scrollViewDidScroll method and check there which UITableViewCell is visible.

This should also help: Best way to check if UITableViewCell is completely visible

Adding an else solved my problem. Where I reseted any changes that were made to the cell.

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM