如何在显示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. 停止执行C#代码
- 3. ASP.NET:停止代码执行
- 4. 停止代码执行Java
- 5. Java停止代码执行?
- 6. 停止执行代码
- 7. 代码(java,多线程)在一行代码后停止执行
- 8. 从外部文件调用执行停止代码
- 9. 停止执行代码时在Page_Load中
- 10. 停止代码在查询中执行
- 11. 的SimpleXMLElement停止执行代码
- 12. file_put_contents停止执行我的代码
- 13. VBA宏代码停止执行
- 14. php on nginx停止执行php代码
- 15. 如何停止PHP代码执行?
- 16. xUnit:从代码停止测试执行
- 17. 停止执行IDE中的代码(BCB)
- 18. 窗体中的代码执行停止
- 19. 代码停止执行过早
- 20. 如何在等待UIAlertView响应时暂停代码执行?
- 21. 暂停代码执行,直到按下UIAlertView按钮?
- 22. 代码在错误后停止运行
- 23. 做如果语句执行后停止代码?
- 24. 在第一个条件后停止执行代码?
- 25. 页面代码在UNION sql查询后停止执行
- 26. 30秒后停止在线程中执行代码
- 27. 停止执行JavaScript代码,然后恢复它
- 28. GO - 函数返回后代码停止执行
- 29. 停止后新形式执行代码加载
- 30. 执行后停止服务
这取决于,特别是你想停止执行什么代码? –
我正在构建一个简单的游戏,我使用委托来通知用户发生了某些事情。如果出现问题,我不会在项目中使用线程。我在主UIViewController中显示警报。 – kernix