ios - 从 block 中读取返回值

标签 ios objective-c

我在我的类中定义了以下 block :

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

我在我的 View Controller 中这样调用这个 block ,并返回一个 bool 值,正如 block 所期望的那样。

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

     return YES; 
}

我将如何设法获取/读取我的类中的返回值?

最佳答案

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

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);

关于ios - 从 block 中读取返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18018435/

相关文章:

ios - 如何在 UITextView 中的空格之间获取单词?

ios - 在 NEPacketTunnelProvider 中获取 UDP 数据包详细信息

Objective-C 到 Swift 3 方法名称更改问题

iphone - 编辑时如何更改 UITextField 中的颜色

ios - 从数据库存储和检索图像时的内存问题

ios - MultipleSelectorRow 自定义

ios - 对 UIControl 的独家触摸

objective-c - XCode 5 单元测试 : starts my app

iphone - 如何在 Iphone 中对齐中心单元格文本?

objective-c - 在 Controller 实例变量中存储现有对象时是否需要 'retain'?