I want to get the user name. A simple text input dialog box. Any simple way to do this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In iOS 5 there is a new and easy way to this. I’m not sure if the implementation is fully complete yet as it’s not a gracious as, say, a
UITableViewCell, but it should definitly do the trick as it is now standard supported in the iOS API. You will not need a private API for this.This renders an alertView like this (screenshot taken from the iPhone 5.0 simulator in XCode 4.2):
When pressing any buttons, the regular delegate methods will be called and you can extract the textInput there like so:
Here I just NSLog the results that were entered. In production code, you should probably keep a pointer to your alertView as a global variable or use the alertView tag to check if the delegate function was called by the appropriate
UIAlertViewbut for this example this should be okay.You should check out the UIAlertView API and you’ll see there are some more styles defined.
Hope this helped!
— EDIT —
I was playing around with the alertView a little and I suppose it needs no announcement that it’s perfectly possible to edit the textField as desired: you can create a reference to the
UITextFieldand edit it as normal (programmatically).Doing this I constructed an alertView as you specified in your original question. Better late than never, right :-)?
This produces this alert:
You can use the same delegate method as I poster earlier to process the result from the input. I’m not sure if you can prevent the
UIAlertViewfrom dismissing though (there is noshouldDismissdelegate function AFAIK) so I suppose if the user input is invalid, you have to put up a new alert (or just reshowthis one) until correct input was entered.Have fun!