我在一个名为 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/