Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is specific to the OP's <code>UIAlertView</code>-wrapping case, and tested only on iOS7: It appears that once a <code>UIAlertView</code> has been initialised with <code>otherButtons:nil</code>, and then has its style set to <code>UIAlertViewStylePlainTextInput</code> it doesn't call its delegate's <code>alertViewShouldEnableFirstOtherButton:</code> to validate input. I'm not sure if this is a bug or intended behaviour but it broke my principle of least astonishment. This is reproducible with the following (I'll assume the delegate's <code>alertViewShouldEnableFirstOtherButton:</code> is implemented):</p> <pre><code>UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; [av setAlertViewStyle:UIAlertViewStylePlainTextInput]; [av addButtonWithTitle:@"OK"]; [av show]; </code></pre> <p>The solution, since UIAlertView happily accepts <code>otherButtons:nil</code>, is to initialise <code>UIAlertView</code> with otherButtonTitles (which can be nil), and iterate over the variadic arguments, as above:</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:otherButtonTitles] autorelease]; // add your [alert setAlertViewStyle:UIAlertViewStylePlainTextInput] etc. as required here if (otherButtonTitles != nil) { 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>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    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