从块读取返回值

7c9*_*fdf 1 objective-c ios

我在班上定义了以下块:

typedef BOOL (^AlertViewShouldEnableFirstOtherButtonHandler)(AlertView *alertView);
Run Code Online (Sandbox Code Playgroud)

我在我的viewcontroller中调用了这个块,并返回一个布尔值,正如块所期望的那样.

 self.alertView.shouldEnableFirstOtherButtonHandler = ^BOOL (AlertView *alertView ) { 

     return YES; 
}
Run Code Online (Sandbox Code Playgroud)

我如何设法获取/读取班级中的返回值?

das*_*ght 7

从块获取返回值的唯一方法是调用它:

UIAlertView *av = [[UIAlertView alloc]
    initWithTitle:@"Quick brown"
    message:@"fox jumps"
    delegate:self
    cancelButtonTitle:@"over the"
    otherButtonTitles:@"Lazy dog",
    nil];
BOOL blockResult = self.alertView.shouldEnableFirstOtherButtonHandler(av);
Run Code Online (Sandbox Code Playgroud)