1

I want a quick input from a user. I know I can put a UITextField in UIAlertView but it's sort of a "hack". Is there an official/alternative way to do this?

It's pretty surprising that there's no control for such a typical scenario.

Thanks

UPDATE: Tried EGOTextFieldAlertView but here's the result: enter image description here

and code:

   EGOTextFieldAlertView *alert = [[EGOTextFieldAlertView alloc] initWithTitle:@"Enter the group name" 
                                                                        message:nil 
                                                                       delegate:self 
                                                              cancelButtonTitle:@"Cancel" 
                                                              otherButtonTitles:@"OK", nil];
    [alert addTextFieldWithLabel:@"Name"];
    [alert show];
    [alert release];
0xSina
  • 20,973
  • 34
  • 136
  • 253

4 Answers4

5

If you're willing to require iOS 5 then it's no longer a hack. UIAlertView now has a alertViewStyle property which, when set to UIAlertViewStylePlainTextInput, adds a single text field to the alert that you can retrieve with -[UIAlertView textFieldAtIndex:].

If you still require 4.3 or earlier, then no, there's no official way to do this and it really is a big "hack" that's on par with calling SPI.

Lily Ballard
  • 182,031
  • 33
  • 381
  • 347
0

Check out EGOTextFieldAlertView.

esqew
  • 42,425
  • 27
  • 92
  • 132
0

If your looking for an alternative way then you can create custom UIView thats looks like alert view and add as subview and make animation like alert view.

Maulik
  • 19,348
  • 14
  • 82
  • 137
0

I had the exact same problem and have fixed it and seems to work in both iOS 4.3 and 5.0. It seems there are some other classes further down throwing off the computing of the offsetY value. Instead of updating offsetY for all non-UIControl classes I changed it to only update it for UILabel classes.

Here is my fix in EGOTextFieldAlertView.m in layoutSubviews

change this line: if(![view isKindOfClass:[UIControl class]]) {
to: if([view isKindOfClass:[UILabel class]]) {

animuson
  • 53,861
  • 28
  • 137
  • 147
skymatt70
  • 53
  • 1
  • 6