Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Add a target to the textfield in a subclassed alertView. You can subclass the alertView and not dismiss <a href="https://stackoverflow.com/questions/2051402/is-it-possible-to-not-dismiss-a-uialertview">as described in this post</a></p> <pre><code>[[alertView textFieldAtIndex:0] addTarget:self action:@selector(textFieldDidChange) forControlEvents:UIControlEventEditingChanged]; </code></pre> <p>Then write a function called textFieldDidChange that checks the current textfield of your alertView and set a boolean value so you know whether or not to dismiss the alert. </p> <pre><code>- (void) textFieldDidChange { NSString *alertViewText = [[alertView textFieldAtIndex:0] text]; if ([alertViewText isEqualToString:@""]) { [alertView setMessage:@"Enter a name please."]; } else { [alertView setMessage:@"Default Message"]; } } </code></pre> <p><strong>* Alternatively, I would suggest disabling "Save" when it is empty and not have to subclass. *</strong></p> <pre><code>- (void) textFieldDidChange { NSString *alertViewText = [[alertView textFieldAtIndex:0] text]; if ([alertViewText isEqualToString:@""]) { [alertView setMessage:@"Enter a name please."]; for (UIViewController *view in alertView.subview) { if ([view isKindOfClass:[UIButton class]]) { UIButton *button = (UIButton *)view; if ([[[button titleLabel] text] isEqualToString:@"Save"]) [button setEnabled:NO]; } } } else { [alertView setMessage:@"Default Message"]; for (UIViewController *view in alertView.subview) { if ([view isKindOfClass:[UIButton class]]) { UIButton *button = (UIButton *)view; if ([[[button titleLabel] text] isEqualToString:@"Save"]) [button setEnabled:YES]; } } } } </code></pre>
    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