37

Is there a way to hide UIAlertView programmatically? Actually I have added a UITextField in UIAlertView and I want to perform the same operation as on "Ok" button press when a user hits the keyboard return key.

ehehhh
  • 1,066
  • 3
  • 16
  • 27
Saurabh
  • 22,743
  • 12
  • 84
  • 133

1 Answers1

81

Call

[theAlertView dismissWithClickedButtonIndex:0 animated:YES];

when you handle the return key.

kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
  • 1
    Thanks for this. If you want it a little more flexible you could also say `[theAlertView dismissWithClickedButtonIndex: theAlertView.cancelButtonIndex animated:YES];` or `[theAlertView dismissWithClickedButtonIndex: theAlertView.firstOtherButtonIndex animated:YES];` to click the first not cancel button. – palme Nov 22 '13 at 09:40