Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can't do this, at least not in the way you're wanting to do it. What you want to do (pass on the variable arguments) requires having an initializer on <code>UIAlertView</code> that accepts a <code>va_list</code>. There isn't one. However, you can use the <code>addButtonWithTitle:</code> method:</p> <pre><code>+ (void)showWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ... { UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:title message:message delegate:delegate cancelButtonTitle:cancelButtonTitle otherButtonTitles:nil] autorelease]; if (otherButtonTitles != nil) { [alert addButtonWithTitle:otherButtonTitles]; va_list args; va_start(args, otherButtonTitles); NSString * title = nil; while(title = va_arg(args,NSString*)) { [alert addButtonWithTitle:title]; } va_end(args); } [alert show]; } </code></pre> <p>This is, of course, very problem-specific. The real answer is "you can't implicitly pass on a variable argument list to a method/function that does not have a <code>va_list</code> parameter". You must therefore find a way around the problem. In the example you gave, you wanted to make an alertView with the titles you passed in. Fortunately for you, the <code>UIAlertView</code> class has a method that you can iteratively call to add buttons, and thereby achieve the same overall effect. If it did not have this method, you'd be out of luck.</p> <p>The other really messy option would be to make it a variadic macro. A variadic macro looks like this:</p> <pre><code>#define SHOW_ALERT(title,msg,del,cancel,other,...) { \ UIAlertView *_alert = [[[UIAlertView alloc] initWithTitle:title message:msg delegate:del cancelButtonTitle:cancel otherButtonTitles:other, ##__VA_ARGS__] autorelease]; \ [_alert show]; \ } </code></pre> <p>However, even with the variadic macro approach, you'd still need a custom macro for each time you wanted to do this. It's not a very solid alternative.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload