Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>UIAlertView</code> with <code>UITextField</code>:</p> <h2>Usage:</h2> <pre><code>NSString *title = NSLocalizedString(@"Your Title",""); NSString *placeholder = NSLocalizedString(@"Placeholder Text",""); NSString *message = NSLocalizedString(@"A message to the user.",""); NSString *cancel = NSLocalizedString(@"Cancel",""); NSString *okay = NSLocalizedString(@"Continue",""); prompt = [[AlertPrompt alloc] initWithTitle:title placeholder:placeholder message:message delegate:self cancelButtonTitle:cancel okButtonTitle:okay]; [prompt show]; [prompt release]; </code></pre> <h2>.h</h2> <pre><code>#import &lt;Foundation/Foundation.h&gt; @interface AlertPrompt : UIAlertView &lt;UITextFieldDelegate&gt; { UITextField *textField; NSString *enteredText; } @property(nonatomic,retain) UITextField *textField; @property (nonatomic, retain, readonly) NSString *enteredText; - (id)initWithTitle:(NSString *)title placeholder:(NSString *)placeholder message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle okButtonTitle:(NSString *)okayButtonTitle; @end </code></pre> <h2>.m</h2> <pre><code>#import ".h" @implementation AlertPrompt @synthesize textField; @synthesize enteredText; #pragma mark - #pragma mark AlertPrompt Delegates - (id)initWithTitle:(NSString *)title placeholder:(NSString *)placeholder message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle okButtonTitle:(NSString *)okayButtonTitle { if (self = [super initWithTitle:title message:message delegate:delegate cancelButtonTitle:cancelButtonTitle otherButtonTitles:okayButtonTitle, nil]) { self.title = title; self.message = [NSString stringWithFormat:@"%@\n\n\n",message]; self.delegate = delegate; UITextField *theTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 75.0f, 260.0, 30.0)]; [theTextField setBackgroundColor:[UIColor clearColor]]; theTextField.borderStyle = UITextBorderStyleRoundedRect; theTextField.textColor = [UIColor blackColor]; theTextField.font = [UIFont systemFontOfSize:18.0]; theTextField.autocapitalizationType = UITextAutocapitalizationTypeWords; theTextField.keyboardAppearance = UIKeyboardAppearanceAlert; theTextField.returnKeyType = UIReturnKeyDone; theTextField.clearButtonMode = UITextFieldViewModeWhileEditing; theTextField.placeholder = placeholder; theTextField.delegate = self; [self insertSubview:theTextField atIndex:0]; self.textField = theTextField; [theTextField release]; CGAffineTransform translate = CGAffineTransformMakeTranslation(0, -10); [self setTransform:translate]; } return self; } - (void)show{ [textField becomeFirstResponder]; [super show]; } - (NSString *)enteredText{ return textField.text; } - (void)dealloc{ [textField resignFirstResponder]; [textField release]; [super dealloc]; } @end </code></pre> <h2>Delegate:</h2> <pre><code>-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if([alertView.title isEqualToString:@"Your Title"]) { if(buttonIndex == 1) { /* get the user iputted text */ NSString *inputValue = [(AlertPrompt *)alertView enteredText]; NSLog(@"User Input: %@",inputValue); { } } </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. 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