Iphone 未调用从NIB加载的自定义单元格的解除锁定

Iphone 未调用从NIB加载的自定义单元格的解除锁定,iphone,uitableview,memory-management,Iphone,Uitableview,Memory Management,我有一个子类UITableViewCell,名为MCProductCell,它是从NIB加载的。问题是,当表被释放时,自定义单元格的dealloc方法甚至不会被调用一次 以下是一些示例代码: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"MCProduct

我有一个子类UITableViewCell,名为MCProductCell,它是从NIB加载的。问题是,当表被释放时,自定义单元格的dealloc方法甚至不会被调用一次

以下是一些示例代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"MCProductCellIdentifier";
    MCProductCell *cell = (MCProductCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
   // Boolean value needed to determine if it is a reused cell or not. If it's not reused we have 
   // to start the thread that loads the image. For reused cells, that thread is started at the
   // end of the scrolling
   BOOL recycled = YES;
   if (cell == nil) {
       NSLog(@"cell alloc");
       recycled = NO;
       NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MCProductCell" owner:self options:nil];
       cell = [nib objectAtIndex:0];
   }
   MCProduct *product = [products objectAtIndex:indexPath.row];
   cell.product = product;
   cell.cartViewController = self;
   cell.productImage = product.cachedThumbnailImage;
   if (product.cachedThumbnailImage == nil) {
       cell.productImage = [ViewControllerUtils getDefaultImage];
       if (!recycled)
           [NSThread detachNewThreadSelector:@selector(loadImage:) toTarget:cell withObject:cell.product.imageThumbnailUrl];
   }

   return cell;
}

出于某种原因,当我第一次展示包含该表的UIViewController时,我的自定义单元格的dealloc方法被调用了一次。 问题是,在dealloc方法中,我希望将单元格作为观察者删除,如果未调用该单元格,则不会将其作为观察者删除。
tableview也是一个出口。

我想,这一定是因为单元格的保留计数没有下降到0。 这意味着你还有另一个选择

我更有经验的同事认为这是因为您使用的是detachNewThreadSelector,它可能保留了单元格

他建议您使用某种类型的异步映像加载映像,例如


祝你好运

“cell.cartViewController”属性是如何定义的?如果它保留了您的控制器对象(self),那么您可能有一个保留周期

我已经评论了我创建一个新线程的所有行,我有同样的问题。不管怎样,谢谢。也许还有其他地方可以保留单元格?我正在使用assign,并调用cartViewController dealloc方法。