我正在尝试创建自定义alertView,但在重写init函数时遇到问题
- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ... {
self = [super initWithTitle:title message:message delegate:delegate cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitles, nil];
//custom initialisaton
return self;
}
如果有多个标题,我如何使用其他按钮标题?
不能-变参数不能从一个函数传递到另一个函数。
然而,有一个变通方法:您可以自己解析参数,然后将它们逐一添加到警报视图中:
self = [super initWithTitle:title
message:message
delegate:delegate
cancelButtonTitle:cancelButtonTitle
otherButtonTitles:nil];
va_list args;
va_start(args, otherButtonTitles);
NSString *title;
for (title = otherButtonTitles; title != nil; title = va_arg(args, NSString *)) {
[self addButtonWithTitle:title];
}
va_end(args);