0

我正在尝试创建自定义警报视图,但在覆盖初始化函数时遇到问题

- (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;
}

如果有多个标题,我如何使用其他按钮标题?

4

1 回答 1

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);
于 2013-08-25T12:47:11.903 回答