自定义完成块为我自己的方法
我刚刚发现完成块:
completion:^(BOOL finished){ }]; 我需要做什么来让我自己的方法采取完成块?
1)定义你自己的完成块,
 typedef void(^myCompletion)(BOOL); 
2)创build一个以完成块为参数的方法,
 -(void) myMethod:(myCompletion) compblock{ //do stuff compblock(YES); } 
3)这是你如何使用它,
 [self myMethod:^(BOOL finished) { if(finished){ NSLog(@"success"); } }]; 

您将块定义为自定义types:
 typedef void (^ButtonCompletionBlock)(int buttonIndex); 
然后用它作为一个方法的参数:
 + (SomeButtonView*)buttonViewWithTitle:(NSString *)title cancelAction:(ButtonCompletionBlock)cancelBlock completionAction:(ButtonCompletionBlock)completionBlock 
在代码中调用它就像其他任何块一样:
 [SomeButtonView buttonViewWithTitle:@"Title" cancelAction:^(int buttonIndex) { NSLog(@"User cancelled"); } completionAction:^(int buttonIndex) { NSLog(@"User tapped index %i", buttonIndex); }]; 
 如果需要触发块,只需调用completionBlock() (其中completionBlock是块的本地副本的名称)。 
块variables在语法上与C中的函数指针类似
由于语法丑陋,所以它们通常是typedefed,但是它们也可以正常声明。
 typedef void (^MyFunc)(BOOL finished); - (void)myMethod:(MyFunc)func { } 
看到这个答案非typedef:
声明一个块方法参数,而不使用typedef