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.

1 Answer 1

81

Call

[theAlertView dismissWithClickedButtonIndex:0 animated:YES];

when you handle the return key.

1
  • 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, 2013 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.