1
我想创建UIActionSheet
的子类,它使用块而不是委派。所以,我创建了以下类:传递可变参数列表
#import <UIKit/UIKit.h>
// Public Interface
typedef void (^FJActionSheetCompletion)(int buttonIndex);
@interface FJActionSheet : UIActionSheet
- (id)initWithTitle:(NSString *)title
completionBlock:(FJActionSheetCompletion)completionBlock
cancelButtonTitle:(NSString *)cancelButtonTitle
destructiveButtonTitle:(NSString *)destructiveButtonTitle
otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
@end
// Private Interface
@interface FJActionSheet() <UIActionSheetDelegate>
{
FJActionSheetCompletion _completionBlock;
}
@end
// Implementation
@implementation FJActionSheet
- (id)initWithTitle:(NSString *)title
completionBlock:(FJActionSheetCompletion)completionBlock
cancelButtonTitle:(NSString *)cancelButtonTitle
destructiveButtonTitle:(NSString *)destructiveButtonTitle
otherButtonTitles:(NSString *)otherButtonTitles, ...
{
self = [super initWithTitle:title
delegate:self
cancelButtonTitle:cancelButtonTitle
destructiveButtonTitle:destructiveButtonTitle
otherButtonTitles:otherButtonTitles];
if (self)
{
_completionBlock = [completionBlock copy];
}
return self;
}
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
_completionBlock(buttonIndex);
}
@end
这个工程除了一个问题:我能不能通过多个字符串为otherButtonTitles
。如果我这样做,我(显然)会得到一个“方法派遣中缺少哨兵”。
我的问题是:如何将otherButtonTitles
参数传递给UIActionSheet
的初始值设定项?
我没有看到它,或者你忘了包含链接? – fabian789
哦是的。支持。 – vikingosegundo
对不起。这是一个漫长的夜晚昨天:) – vikingosegundo