ios weakself strongself

    

    LRWeakSelf(self)

//weak strong self

#define LRWeakSelf(type)  __weak typeof(type) weak##type = type;

#define LRStrongSelf(type)  __strong typeof(type) type = weak##type;





ChattingSetModel *check = [ChattingSetModel value2ModelWithTitle:@"群主审核新成员" open:self.group.masterVerify didClickBlock:nil];

    check.switchBlock = ^(BOOL open) {

        [[DDGroupModule instance] groupMasterVerity:self.group.groupId enable:open result:^(BOOL result, NSError *error) {


        
LRStrongSelf(self)

            if (error) {

                [self showHubTitle:self.view titleText:@"设置失败" location:FULL_HEIGHT/2-80];

            }

        }];

    };此处导致界面无法释放,原因:http://www.code4app.com/blog-864937-1150.html,LRStrongSelf要在block执行之后便执行,如果后面有使用self而不是weakself调用的话很容易出现循环引用,导致界面无法释放,如上.(##宏定义代表拼接字符串.)

LRStrongSelf(shop)Block内部的强引用,而不是外部强引用。所以Block内部声明的强引用不管怎么访问都是不会干扰外部的对象,也不会自动产生一个强引用。所以没有循环引用




http://www.code4app.com/blog-864937-1150.html这个链接相当值钱,~~







猜你喜欢

转载自blog.csdn.net/georgehenrywilliam/article/details/80486297
ios