我在班上定义了以下块:
typedef BOOL (^AlertViewShouldEnableFirstOtherButtonHandler)(AlertView *alertView);
我在我的viewcontroller中调用了这个块,并返回一个布尔值,正如块所期望的那样。
self.alertView.shouldEnableFirstOtherButtonHandler = ^BOOL (AlertView *alertView ) {
return YES;
}
我如何设法获取/读取班级中的返回值?
答案 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);