简体   繁体   English

使用UIText输入处理从UIAlert调用的UIAlert代码的位置

[英]Where to handle UIAlert code called from UIAlert with UIText input

I have a Popover with 3 buttons. 我有一个带有3个按钮的Popover。

One of these buttons is linked to an IBAction method that displays a UIAlert dialog using setAlertViewStyle:UIAletViewStylePlainTextInput in order to obtain user input. 这些按钮之一链接到IBAction方法,该方法使用setAlertViewStyle:UIAletViewStylePlainTextInput显示UIAlert对话框,以获得用户输入。

Based on the user's input, I want to display another UIAlert showing either CORRECT or INCORRECT based on some dictionary lookup. 根据用户的输入,我想显示另一个UIAlert,该UIAlert根据某些字典查找显示正确或不正确。

My challenge is where to put the 2nd UIAlert code. 我的挑战是在哪里放置第二UIAlert代码。 I've tried putting it into an alertView:willDismissWithButtonIndex ; 我尝试将其放入alertView:willDismissWithButtonIndex ; I've also tried it in alertView:clickedButtonAtIndex . 我也曾在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. alertView:clickedButtonAtIndex:将是正确的使用方法。 Are you differentiating between the alertViews somehow, like with the tag property? 您是否以某种方式(例如使用tag属性)区分了alertViews? You might be running code for the right buttonIndex but the wrong alertView . 您可能正在为正确的buttonIndex但错误的alertView运行代码。

If you're using Popovers, I assume you're developing on an iPad? 如果您使用的是Popovers,我想您是在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). 我建议您将UIActionSheet用于初始弹出窗口,而不是使用3个按钮手动定义弹出窗口(除非您对此有一些图形上的需要)。

With a UIActionSheet, you can then specify in the UIActionSheet delegate the logic for when to show the proper alert view. 然后,使用UIActionSheet,可以在UIActionSheet委托中指定何时显示正确的警报视图的逻辑。 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. iPad上的UIActionSheets默认显示在Popovers中,因此这也应减少一些视图代码,并通常使iOS应用程序的体验更为标准。

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. 如果您绝对必须有多个弹出窗口(在iOS设计中通常是禁止的),那么上面提到的Anthony正确地利用了tag属性,然后关闭了数字标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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