EXC_BAD_ACCESS使用块时

时间:2017-06-15 08:20:19

标签: ios objective-c objective-c-blocks exc-bad-access objective-c-category

在SecondViewController中使用过块。创建块作为属性并添加了复制属性。但是,当它达到**self.didSelectImageInImagePickVC(name);**

时会崩溃

SecondViewController.h

@property (nonatomic, copy) void(^didSelectImageInImagePickVC)(NSString *imageName);

SecondViewController.m

NSString *name = [resultArray objectAtIndex:indexPath.item];

self.didSelectImageInImagePickVC(name);

Firstviewcontroller.m

__typeof(&*self) __weak weakSelfImagePick = self;

[[SecondViewController sharedInstance] setDidSelectImageInImagePickVC:^(NSString *imageName){
    NSLog(@"Image: %@", imageName);
}];

有没有人有任何想法?提前谢谢。

1 个答案:

答案 0 :(得分:0)

尝试访问secondViewController的存在块,如下所示。

有问题你的是创建新块

[SecondViewController sharedInstance]. didSelectImageInImagePickVC = ^(NSString * imageName) {
        // here your image name
    };

你需要为你的类的块属性分配参数块。

-(void)setDidSelectImageInImagePickVC:(yourblock)block{
   self.didSelectImageInImagePickVC = block
}