我正在尝试创建自定义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;
}
如果有多个标题,我该如何使用其他按钮标题?
答案 0 :(得分:1)
你不能 - 变量参数不能从函数传递给另一个函数。
但是有一种解决方法:您可以自己解析参数,然后将它们逐个添加到警报视图中:
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);