如何在顯示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