ios - 这是一个 objective-c block 吗?

标签 ios objective-c

我在一个名为 SIAlertView 的开源库中看到了一些代码,我不确定它在做什么?具体是下面两行?什么是 SIAleartViewHandler,因为它不是 SIAlertView 库中的一个类?

typedef void(^SIAlertViewHandler)(SIAlertView *alertView);
@property (nonatomic, copy) SIAlertViewHandler willShowHandler;

SIAlertView.h

typedef void(^SIAlertViewHandler)(SIAlertView *alertView);
@property (nonatomic, copy) SIAlertViewHandler willShowHandler;
@property (nonatomic, copy) SIAlertViewHandler didShowHandler;
@property (nonatomic, copy) SIAlertViewHandler willDismissHandler;
@property (nonatomic, copy) SIAlertViewHandler didDismissHandler;

SIAlertView.m

[self transitionInCompletion:^{
    if (self.didShowHandler) {
        self.didShowHandler(self);
    }
    [[NSNotificationCenter defaultCenter] postNotificationName:SIAlertViewDidShowNotification object:self userInfo:nil];

    [SIAlertView setAnimating:NO];

    NSInteger index = [[SIAlertView sharedQueue] indexOfObject:self];
    if (index < [SIAlertView sharedQueue].count - 1) {
        [self dismissAnimated:YES cleanup:NO]; // dismiss to show next alert view
    }
}];

#pragma mark - SIAlertItem

@interface SIAlertItem : NSObject

@property (nonatomic, copy) NSString *title;
@property (nonatomic, assign) SIAlertViewButtonType type;
@property (nonatomic, copy) SIAlertViewHandler action;

@end

@implementation SIAlertItem

@end

最佳答案

第一行 (typedef void(^SIAlertViewHandler)(SIAlertView *alertView);) 定义了一种 block 类型,称为 SIAlertViewHandler

第二行 (@property (nonatomic, copy) SIAlertViewHandler willShowHandler;) 定义了一个属性,该属性将存储该 block 类型的实例。

关于ios - 这是一个 objective-c block 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18045791/

相关文章:

ios - UITableView 行高基于单元格内容

iphone - 如何在iPhone模拟器中模拟重要的位置更新

android - iOS/Android 移动设备上的 Hyperledger

ios - 强制 iOS CloudKit 同步更新,将所有记录下载到本地设备

ios - 当 iPhone 处于锁定状态的后台模式时,NSDATA 没有写入文档目录?

iOS 7.1 : Border around search bar

iphone - ViewController = _ViewController 的意思

ios - UIDatePicker 结果到 dateByAddingTimeInterval

iphone - 使用 Game Center 登录在远程服务器上引导登录

ios - xcodebuild - 设置构建目录不会生成 dSYM