从块读取返回值

时间:2013-08-02 13:43:45

标签: ios objective-c

我在班上定义了以下块:

typedef BOOL (^AlertViewShouldEnableFirstOtherButtonHandler)(AlertView *alertView);

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

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

     return YES; 
}

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

1 个答案:

答案 0 :(得分: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);
相关问题