1

假设我在一个类中有一个函数,它显示一个警报:

- (void)showErrorWithTitle:(NSString *)title message:(NSString *)message
         cancelButtonTitle:(NSString *)cancelButtonTitle 
         otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;

- (void)showErrorWithTitle:(NSString *)title message:(NSString *)message
         cancelButtonTitle:(NSString *)cancelButtonTitle 
         otherButtonTitles:(NSString *)otherButtonTitles, ... {

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
                                                    message:message
                                                   delegate:nil
                                          cancelButtonTitle:cancelButtonTitle
                                          otherButtonTitles:nil];

    va_list args;
    va_start(args, otherButtonTitles);
    for (NSString *arg = otherButtonTitles; arg != nil; arg = va_arg(args, NSString*))
    {
        [alert addButtonWithTitle:arg];
    }
    va_end(args);

    [alert show];
    [alert release];
}

我有一个包装类,其中一个方法调用此方法。我的问题是我必须如何实现这个方法?

此解决方案不起作用:

- (void)showErrorWithTitle1:(NSString *)title message:(NSString *)message 
          cancelButtonTitle:(NSString *)cancelButtonTitle 
          otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;

- (void)showErrorWithTitle1:(NSString *)title message:(NSString *)message 
          cancelButtonTitle:(NSString *)cancelButtonTitle 
          otherButtonTitles:(NSString *)otherButtonTitles, ... {

    [[Someclass intance] showErrorWithTitle:title
                                    message:message
                          cancelButtonTitle:cancelButtonTitle
                          otherButtonTitles:otherButtonTitles, nil];
}

调用:

[self showErrorWithTitle1:@"Hello"
                 message:@"Example"
       cancelButtonTitle:@"No"
       otherButtonTitles:@"Yes, Maybe", nil];
4

0 回答 0