在block中為了防止循環(huán)引用會(huì)使用weakSelf 或者 strongSelf
那么什么時(shí)候使用weakSelf,什么時(shí)候使用strongSelf蔚出;
1.如果block內(nèi)部需要訪問(wèn)self的方法矢空,屬性或者實(shí)例變量需要使用weakSelf敷矫;
2.如果在block內(nèi)需要多次訪問(wèn)self肉微,則需要使用strongSelf
3.如果在block內(nèi)部存在多線程環(huán)境訪問(wèn)self辽慕,則需要使用strongSelf
__weak typeof(self)weakSelf = self;
_collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
__strong typeof(self)strongSelf = weakSelf;
dispatch_async(dispatch_get_main_queue(), ^{
[strongSelf loadData];
});
}];