简体   繁体   中英

EXC_BAD_ACCESS When using blocks

Have used block in SecondViewController. Created block as property and added copy attribute. But, It crashes when it reaches **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);
}];

Does anyone have any idea? Thanks in advance.

Try to access secondViewController's exist block as below.

in question your are created new block

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

OR

you need to assign argument block to your class's block property.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM