如何在显示UIAlertView之后停止代码执行,直到用户按下确定按钮?如果这是一个问题,有什么解决方法?调用后停止执行代码UIAlertView
2
A
回答
7
端起来:
myAlert.tag = UserConfirmationAlert;
然后在你的UIAlertDelegate,可以将开关/箱中,像这样执行所需的方法
...
[alert show];
while ((!alert.hidden) && (alert.superview != nil))
{
[[NSRunLoop currentRunLoop] limitDateForMode:NSDefaultRunLoopMode];
}
1
看来你不想执行紧跟在[alertview show]方法后面的代码。为了实现这些,将这些代码行添加到方法中,并在以下UIAlertView代理中调用该方法。
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == OKButtonIndex)
{
// Issue a call to a method you have created that encapsulates the
// code you want to execute upon a successful tap.
// [self thingsToDoUponAlertConfirmation];
}
}
现在,如果你要你的类中有一个以上的UIAlertView中,你要确保你可以很容易地处理每一个UIAlertView中。您可以使用UIAlertView上的NSEnum和标签设置来完成此操作。
如果你有三个提醒,在您的类的顶部您@interface之前声明NSEnum像这样:
// alert codes for alertViewDelegate // AZ 09222014
typedef NS_ENUM(NSInteger, AlertTypes)
{
UserConfirmationAlert = 1, // these are all the names of each alert
BadURLAlert,
InvalidChoiceAlert
};
然后,右键在你的[警报显示],警报的标签设置为被显示。使用这种
// Alert handling code
#pragma mark - UIAlertViewDelegate - What to do when a dialog is dismissed.
// We are only handling one button alerts here. Add a check for the buttonIndex == 1
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (alertView.tag) {
case UserConfirmationAlert:
[self UserConfirmationAlertSuccessPart2];
alertView.tag = 0;
break;
case BadURLAlert:
[self BadURLAlertAlertSuccessPart2];
alertView.tag = 0;
break;
case InvalidChoiceAlert:
[self InvalidChoiceAlertAlertSuccessPart2];
alertView.tag = 0;
break;
default:
NSLog(@"No tag identifier set for the alert which was trapped.");
break;
}
}
相关问题
- 1. 执行代码后停止Docker容器
- 2. 停止执行代码
- 3. ASP.NET:停止代码执行
- 4. 代码(java,多线程)在一行代码后停止执行
- 5. 从外部文件调用执行停止代码
- 6. 停止执行代码时在Page_Load中
- 7. 停止代码在查询中执行
- 8. xUnit:从代码停止测试执行
- 9. 停止执行IDE中的代码(BCB)
- 10. 窗体中的代码执行停止
- 11. 的SimpleXMLElement停止执行代码
- 12. 如何在等待UIAlertView响应时暂停代码执行?
- 13. 暂停代码执行,直到按下UIAlertView按钮?
- 14. 代码在错误后停止运行
- 15. 做如果语句执行后停止代码?
- 16. 页面代码在UNION sql查询后停止执行
- 17. 30秒后停止在线程中执行代码
- 18. 停止后新形式执行代码加载
- 19. 在VS2008中点击停止调试后仍然执行asp.net代码
- 20. getImageData后停止代码
- 21. 停止执行调用的execfile
- 22. C代码停止运行
- 23. (ASP classic)停止/阻止其他代码执行而不会中断Javascript执行
- 24. 如何在redirect_to被调用后停止执行
- 25. 在递归函数调用后执行循环停止 - javascript
- 26. 停止调用$ http拦截器之后执行角度$超时
- 27. 如何使用的try-catch不停止执行代码
- 28. 在当前正在执行的代码行上停止调试器
- 29. 当PHP到达一行代码时,PHP停止执行
- 30. ipython 5.1.0在执行输入后停止
这取决于,特别是你想停止执行什么代码? –
我正在构建一个简单的游戏,我使用委托来通知用户发生了某些事情。如果出现问题,我不会在项目中使用线程。我在主UIViewController中显示警报。 – kernix