12

I want take player name as input by using UIAlertView. Is it possible to add textField on the UIAlertView?

stefanB
  • 77,323
  • 27
  • 116
  • 141
SST
  • 2,040
  • 5
  • 26
  • 42

3 Answers3

31

Since iOS 5, UIAlertView provides this: change the alertViewStyle property to one of the following:

UIAlertViewStylePlainTextInput (1 text field)
UIAlertViewStyleSecureTextInput (1 password field)
UIAlertViewStyleLoginAndPasswordInput (both a text field and password field)

Then use textFieldAtIndex: to get the text field you want. This way, you can even use the alertViewShouldEnableFirstOtherButton: delegate method to enable the button.

Tustin2121
  • 2,058
  • 2
  • 25
  • 38
11

Yes, it's definitely possible, and it isn't a hack. You would need to subclass UIAlertView and place controls into it. Since it's a subclass, it will retain the same look & feel, etc.

For full details, see this tutorial by Jeff LaMarche (co-author of Beginning iPhone Development, from Apress).

Jim Dovey
  • 11,166
  • 2
  • 33
  • 40
1

Yes, but not without some hacking, see this previous question. You'd have to directly manipulate the UIAlertView's subviews and add a UITextField and then resize the UIAlertView's frame. You're better off creating your own view.

Community
  • 1
  • 1
drewh
  • 10,077
  • 7
  • 34
  • 43