Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>OK After a ton of digging, here is the result.</p> <p>Firstly, putting in 'UITextField UIAlertView' into SO's search returns dozens of hits.</p> <p>It turns out there is a method for doing this, <a href="https://stackoverflow.com/questions/1767680/need-new-way-to-add-a-uitextfield-to-a-uialertview">Need new way to add a UITextField to a UIAlertView</a> but it is private API :|</p> <p>Pretty much every other solution involves hacking a UIAlertView, which is ugly: <a href="http://junecloud.com/journal/code/displaying-a-password-or-text-entry-prompt-on-the-iphone.html" rel="nofollow noreferrer">http://junecloud.com/journal/code/displaying-a-password-or-text-entry-prompt-on-the-iphone.html</a><br> <a href="http://iphone-dev-tips.alterplay.com/2009/12/username-and-password-uitextfields-in.html" rel="nofollow noreferrer">http://iphone-dev-tips.alterplay.com/2009/12/username-and-password-uitextfields-in.html</a><br> <a href="https://github.com/josecastillo/EGOTextFieldAlertView/" rel="nofollow noreferrer">https://github.com/josecastillo/EGOTextFieldAlertView/</a><br> <a href="https://stackoverflow.com/questions/409599/how-to-move-the-buttons-in-a-uialertview-to-make-room-for-an-inserted-uitextfield">How to move the buttons in a UIAlertView to make room for an inserted UITextField?</a><br> ^ MrGando's answer is neat<br> <a href="http://iphonedevelopment.blogspot.com/2009/02/alert-view-with-prompt.html" rel="nofollow noreferrer">http://iphonedevelopment.blogspot.com/2009/02/alert-view-with-prompt.html</a><br> <a href="https://stackoverflow.com/questions/4560346/getting-text-from-uialertview">Getting text from UIAlertView</a> </p> <p>The only proper solution I found (ie coding from scratch from a UIView) is here: <a href="https://github.com/TomSwift/TSAlertView" rel="nofollow noreferrer">https://github.com/TomSwift/TSAlertView</a></p> <p>This is all it takes:</p> <pre><code>- (IBAction) importTap { TSAlertView* av = [[[TSAlertView alloc] init] autorelease]; av.title = @"Enter URL"; av.message = @""; [av addButtonWithTitle: @"Ok"]; [av addButtonWithTitle: @"Cancel"]; av.style = TSAlertViewStyleInput; av.buttonLayout = TSAlertViewButtonLayoutNormal; av.delegate = self; av.inputTextField.text = @"http://"; [av show]; } // after animation - (void) alertView: (TSAlertView *) alertView didDismissWithButtonIndex: (NSInteger) buttonIndex { // cancel if( buttonIndex == 1 ) return; LOG( @"Got: %@", alertView.inputTextField.text ); } </code></pre> <p>and Presto!</p> <p><img src="https://i.stack.imgur.com/DU7eK.png" alt="enter image description here"></p>
 

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