简体   繁体   中英

Where to handle UIAlert code called from UIAlert with UIText input

I have a Popover with 3 buttons.

One of these buttons is linked to an IBAction method that displays a UIAlert dialog using setAlertViewStyle:UIAletViewStylePlainTextInput in order to obtain user input.

Based on the user's input, I want to display another UIAlert showing either CORRECT or INCORRECT based on some dictionary lookup.

My challenge is where to put the 2nd UIAlert code. I've tried putting it into an alertView:willDismissWithButtonIndex ; I've also tried it in alertView:clickedButtonAtIndex . In both cases, although the 2nd alert is displayed, upon clicking the OK button, the same alert is displayed again…ad infinitum.

Looking for advice on how to avoid this loop; where it would be best to put this code?

Thanks Tony.

alertView:clickedButtonAtIndex: would be the correct method to use. Are you differentiating between the alertViews somehow, like with the tag property? You might be running code for the right buttonIndex but the wrong alertView .

If you're using Popovers, I assume you're developing on an iPad? I would recommend then using a UIActionSheet for your initial popover, rather than manually defining a popover with 3 buttons (unless you have some graphical need for doing so).

With a UIActionSheet, you can then specify in the UIActionSheet delegate the logic for when to show the proper alert view. UIActionSheets on iPad are presented by default in Popovers, so that should also reduce some of your view code, and make the experience more standard with iOS apps in general.

In the event you absolutely must have multiple popups (which is a general no-no in iOS design), what Anthony mentioned above is correct to utilize the tag property, and then switch off of the numeric tags.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM