Search code examples
iosobjective-cblock

How to check a block if is realize?


In my code, if I use the block directly:

- (IBAction)checkPendingAction:(UIButton *)sender {
    self.block(sender.titleLabel.text);  // if the block is no realize, there will report EXC_BAD_ACCESS(code=x, address=0x11xx)
}

If I use delegate, I can use the below code to check my delegate and delegate method if is realize:

if ([self.delegate respondsToSelector:@selector(myDelegateMethod:)]) {
    [self.delegate tabBarClickWriteButton:self];
}

So, can I check the block if is realize in iOS?


Solution

  • You need check block as below

    if (self.yourblock != nil) { 
        self.yourblock(self.titleLabel.text);
     }