You define the block as a custom type:
typedef void (^ButtonCompletionBlock)(int buttonIndex);
Then use it as an argument to the method:
+ (SomeButtonView*)buttonViewWithTitle:(NSString *)title cancelAction:(ButtonCompletionBlock)cancelBlock completionAction:(ButtonCompletionBlock)completionBlock
When calling this code, it is like any other block:
[SomeButtonView buttonViewWithTitle:@"Title" cancelAction:^(int buttonIndex) { NSLog(@"User cancelled"); } completionAction:^(int buttonIndex) { NSLog(@"User tapped index %i", buttonIndex); }];
If it's time to start the block, just call completionBlock() (where completionBlock is the name of your local copy of the block).
jszumski May 01 '13 at 18:36 2013-05-01 18:36
source share