thefansofjay
thefansofjay
2015-11-30 10:32

IOS block强引用循环问题,下面的代码为什么能避免强引用循环

1
  • ios

下面的代码为什么能避免强引用循环?

    cell.thumbnailView.image = item.thumbnail;

__weak BNRItemCell *weakCell = cell;

cell.actionBlock = ^{
    NSLog(@"Going to show image for %@", item);

    BNRItemCell *strongCell = weakCell;

    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
        NSString *itemKey = item.itemKey;
        // If there is no image, we don't need to display anything
        UIImage *img = [[BNRImageStore sharedStore] imageForKey:itemKey];
        if (!img) {
            return; }
        // Make a rectangle for the frame of the thumbnail relative to
        // our table view
        CGRect rect = [self.view convertRect:strongCell.thumbnailView.bounds
                                    fromView:strongCell.thumbnailView];
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

0条回答