Commit 3c805dad authored by zyy's avatar zyy

防止对象被释放而又用weak指针调用所带来的异常

parent d402958e
...@@ -56,7 +56,8 @@ ...@@ -56,7 +56,8 @@
_previewView.model = self.model; _previewView.model = self.model;
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
[_previewView setSingleTapGestureBlock:^{ [_previewView setSingleTapGestureBlock:^{
[weakSelf signleTapAction]; __strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf signleTapAction];
}]; }];
[self.view addSubview:_previewView]; [self.view addSubview:_previewView];
} }
......
...@@ -370,7 +370,8 @@ ...@@ -370,7 +370,8 @@
// if over time, dismiss HUD automatic // if over time, dismiss HUD automatic
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(self.timeout * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(self.timeout * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf hideProgressHUD]; __strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf hideProgressHUD];
}); });
} }
......
...@@ -460,10 +460,13 @@ static CGFloat itemMargin = 5; ...@@ -460,10 +460,13 @@ static CGFloat itemMargin = 5;
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
__weak typeof(_numberImageView.layer) weakLayer = _numberImageView.layer; __weak typeof(_numberImageView.layer) weakLayer = _numberImageView.layer;
cell.didSelectPhotoBlock = ^(BOOL isSelected) { cell.didSelectPhotoBlock = ^(BOOL isSelected) {
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)weakSelf.navigationController; __strong typeof(weakCell) strongCell = weakCell;
__strong typeof(weakSelf) strongSelf = weakSelf;
__strong typeof(weakLayer) strongLayer = weakLayer;
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)strongSelf.navigationController;
// 1. cancel select / 取消选择 // 1. cancel select / 取消选择
if (isSelected) { if (isSelected) {
weakCell.selectPhotoButton.selected = NO; strongCell.selectPhotoButton.selected = NO;
model.isSelected = NO; model.isSelected = NO;
NSArray *selectedModels = [NSArray arrayWithArray:tzImagePickerVc.selectedModels]; NSArray *selectedModels = [NSArray arrayWithArray:tzImagePickerVc.selectedModels];
for (TZAssetModel *model_item in selectedModels) { for (TZAssetModel *model_item in selectedModels) {
...@@ -472,20 +475,20 @@ static CGFloat itemMargin = 5; ...@@ -472,20 +475,20 @@ static CGFloat itemMargin = 5;
break; break;
} }
} }
[weakSelf refreshBottomToolBarStatus]; [strongSelf refreshBottomToolBarStatus];
} else { } else {
// 2. select:check if over the maxImagesCount / 选择照片,检查是否超过了最大个数的限制 // 2. select:check if over the maxImagesCount / 选择照片,检查是否超过了最大个数的限制
if (tzImagePickerVc.selectedModels.count < tzImagePickerVc.maxImagesCount) { if (tzImagePickerVc.selectedModels.count < tzImagePickerVc.maxImagesCount) {
weakCell.selectPhotoButton.selected = YES; strongCell.selectPhotoButton.selected = YES;
model.isSelected = YES; model.isSelected = YES;
[tzImagePickerVc.selectedModels addObject:model]; [tzImagePickerVc.selectedModels addObject:model];
[weakSelf refreshBottomToolBarStatus]; [strongSelf refreshBottomToolBarStatus];
} else { } else {
NSString *title = [NSString stringWithFormat:[NSBundle tz_localizedStringForKey:@"Select a maximum of %zd photos"], tzImagePickerVc.maxImagesCount]; NSString *title = [NSString stringWithFormat:[NSBundle tz_localizedStringForKey:@"Select a maximum of %zd photos"], tzImagePickerVc.maxImagesCount];
[tzImagePickerVc showAlertWithTitle:title]; [tzImagePickerVc showAlertWithTitle:title];
} }
} }
[UIView showOscillatoryAnimationWithLayer:weakLayer type:TZOscillatoryAnimationToSmaller]; [UIView showOscillatoryAnimationWithLayer:strongLayer type:TZOscillatoryAnimationToSmaller];
}; };
return cell; return cell;
} }
...@@ -576,9 +579,11 @@ static CGFloat itemMargin = 5; ...@@ -576,9 +579,11 @@ static CGFloat itemMargin = 5;
// 提前定位 // 提前定位
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
[[TZLocationManager manager] startLocationWithSuccessBlock:^(CLLocation *location, CLLocation *oldLocation) { [[TZLocationManager manager] startLocationWithSuccessBlock:^(CLLocation *location, CLLocation *oldLocation) {
weakSelf.location = location; __strong typeof(weakSelf) strongSelf = weakSelf;
strongSelf.location = location;
} failureBlock:^(NSError *error) { } failureBlock:^(NSError *error) {
weakSelf.location = nil; __strong typeof(weakSelf) strongSelf = weakSelf;
strongSelf.location = nil;
}]; }];
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera; UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
...@@ -613,16 +618,19 @@ static CGFloat itemMargin = 5; ...@@ -613,16 +618,19 @@ static CGFloat itemMargin = 5;
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
photoPreviewVc.isSelectOriginalPhoto = _isSelectOriginalPhoto; photoPreviewVc.isSelectOriginalPhoto = _isSelectOriginalPhoto;
[photoPreviewVc setBackButtonClickBlock:^(BOOL isSelectOriginalPhoto) { [photoPreviewVc setBackButtonClickBlock:^(BOOL isSelectOriginalPhoto) {
weakSelf.isSelectOriginalPhoto = isSelectOriginalPhoto; __strong typeof(weakSelf) strongSelf = weakSelf;
[weakSelf.collectionView reloadData]; strongSelf.isSelectOriginalPhoto = isSelectOriginalPhoto;
[weakSelf refreshBottomToolBarStatus]; [strongSelf.collectionView reloadData];
[strongSelf refreshBottomToolBarStatus];
}]; }];
[photoPreviewVc setDoneButtonClickBlock:^(BOOL isSelectOriginalPhoto) { [photoPreviewVc setDoneButtonClickBlock:^(BOOL isSelectOriginalPhoto) {
weakSelf.isSelectOriginalPhoto = isSelectOriginalPhoto; __strong typeof(weakSelf) strongSelf = weakSelf;
[weakSelf doneButtonClick]; strongSelf.isSelectOriginalPhoto = isSelectOriginalPhoto;
[strongSelf doneButtonClick];
}]; }];
[photoPreviewVc setDoneButtonClickBlockCropMode:^(UIImage *cropedImage, id asset) { [photoPreviewVc setDoneButtonClickBlockCropMode:^(UIImage *cropedImage, id asset) {
[weakSelf didGetAllPhotos:@[cropedImage] assets:@[asset] infoArr:nil]; __strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf didGetAllPhotos:@[cropedImage] assets:@[asset] infoArr:nil];
}]; }];
[self.navigationController pushViewController:photoPreviewVc animated:YES]; [self.navigationController pushViewController:photoPreviewVc animated:YES];
} }
......
...@@ -50,13 +50,15 @@ ...@@ -50,13 +50,15 @@
self.previewView = [[TZPhotoPreviewView alloc] initWithFrame:CGRectZero]; self.previewView = [[TZPhotoPreviewView alloc] initWithFrame:CGRectZero];
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
[self.previewView setSingleTapGestureBlock:^{ [self.previewView setSingleTapGestureBlock:^{
if (weakSelf.singleTapGestureBlock) { __strong typeof(weakSelf) strongSelf = weakSelf;
weakSelf.singleTapGestureBlock(); if (strongSelf.singleTapGestureBlock) {
strongSelf.singleTapGestureBlock();
} }
}]; }];
[self.previewView setImageProgressUpdateBlock:^(double progress) { [self.previewView setImageProgressUpdateBlock:^(double progress) {
if (weakSelf.imageProgressUpdateBlock) { __strong typeof(weakSelf) strongSelf = weakSelf;
weakSelf.imageProgressUpdateBlock(progress); if (strongSelf.imageProgressUpdateBlock) {
strongSelf.imageProgressUpdateBlock(progress);
} }
}]; }];
[self addSubview:self.previewView]; [self addSubview:self.previewView];
...@@ -419,7 +421,8 @@ ...@@ -419,7 +421,8 @@
_previewView = [[TZPhotoPreviewView alloc] initWithFrame:CGRectZero]; _previewView = [[TZPhotoPreviewView alloc] initWithFrame:CGRectZero];
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
[_previewView setSingleTapGestureBlock:^{ [_previewView setSingleTapGestureBlock:^{
[weakSelf signleTapAction]; __strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf signleTapAction];
}]; }];
[self addSubview:_previewView]; [self addSubview:_previewView];
} }
......
...@@ -427,13 +427,17 @@ ...@@ -427,13 +427,17 @@
__weak typeof(_collectionView) weakCollectionView = _collectionView; __weak typeof(_collectionView) weakCollectionView = _collectionView;
__weak typeof(photoPreviewCell) weakCell = photoPreviewCell; __weak typeof(photoPreviewCell) weakCell = photoPreviewCell;
[photoPreviewCell setImageProgressUpdateBlock:^(double progress) { [photoPreviewCell setImageProgressUpdateBlock:^(double progress) {
weakSelf.progress = progress; __strong typeof(weakSelf) strongSelf = weakSelf;
__strong typeof(weakTzImagePickerVc) strongTzImagePickerVc = weakTzImagePickerVc;
__strong typeof(weakCollectionView) strongCollectionView = weakCollectionView;
__strong typeof(weakCell) strongCell = weakCell;
strongSelf.progress = progress;
if (progress >= 1) { if (progress >= 1) {
if (weakSelf.isSelectOriginalPhoto) [weakSelf showPhotoBytes]; if (strongSelf.isSelectOriginalPhoto) [strongSelf showPhotoBytes];
if (weakSelf.alertView && [weakCollectionView.visibleCells containsObject:weakCell]) { if (strongSelf.alertView && [strongCollectionView.visibleCells containsObject:strongCell]) {
[weakTzImagePickerVc hideAlertView:weakSelf.alertView]; [strongTzImagePickerVc hideAlertView:strongSelf.alertView];
weakSelf.alertView = nil; strongSelf.alertView = nil;
[weakSelf doneButtonClick]; [strongSelf doneButtonClick];
} }
} }
}]; }];
...@@ -441,7 +445,8 @@ ...@@ -441,7 +445,8 @@
cell.model = model; cell.model = model;
[cell setSingleTapGestureBlock:^{ [cell setSingleTapGestureBlock:^{
[weakSelf didTapPreviewCell]; __strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf didTapPreviewCell];
}]; }];
return cell; return cell;
} }
......
...@@ -362,9 +362,11 @@ ...@@ -362,9 +362,11 @@
// 提前定位 // 提前定位
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
[[TZLocationManager manager] startLocationWithSuccessBlock:^(CLLocation *location, CLLocation *oldLocation) { [[TZLocationManager manager] startLocationWithSuccessBlock:^(CLLocation *location, CLLocation *oldLocation) {
weakSelf.location = location; __strong typeof(weakSelf) strongSelf = weakSelf;
strongSelf.location = location;
} failureBlock:^(NSError *error) { } failureBlock:^(NSError *error) {
weakSelf.location = nil; __strong typeof(weakSelf) strongSelf = weakSelf;
strongSelf.location = nil;
}]; }];
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera; UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment