ios – 警告:UIAlertController已经呈现

前端之家收集整理的这篇文章主要介绍了ios – 警告:UIAlertController已经呈现前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是 swift和XCode的新手所以请原谅我可能非常混乱的代码
运行我的代码时,我收到以下警告:
警告:尝试出示已经出现的内容

我已经检查了论坛并发现了一个关于该问题的帖子….我应用了建议的帮助,如:

  1. if presentedViewController !== nil {
  2. self.presentViewController(alertController,animated: true,completion: nil)
  3. } else{
  4. self.dismissViewControllerAnimated(false,completion: nil)
  5. self.presentViewController(alertController,completion: nil)
  6. }

但是,它仍然给了我同样的警告….所以我想我一定做错了.如果有人可以帮助我,那将是很棒的:)如果有任何关于我如何“清理”我的代码的建议,我感激不尽:)

  1. import UIKit
  2.  
  3. class ViewController: UIViewController {
  4.  
  5. @IBOutlet var Label: UILabel!
  6.  
  7. @IBOutlet var ukFlag: UITextView!
  8.  
  9. @IBOutlet var movie: UITextView!
  10.  
  11. @IBOutlet var piano: UITextView!
  12.  
  13. @IBOutlet var book: UITextView!
  14.  
  15. @IBOutlet var dance: UITextView!
  16.  
  17. @IBOutlet var paint: UITextView!
  18.  
  19. @IBOutlet var row: UITextView!
  20.  
  21. @IBOutlet var envelope: UITextView!
  22.  
  23. @IBOutlet var dragon: UITextView!
  24.  
  25. @IBOutlet var instagram: UITextView!
  26.  
  27.  
  28. func londonPuzzle(sender: UIPanGestureRecognizer) {
  29. let translation = sender.translationInView(self.view)
  30. sender.view!.center = CGPoint(x: sender.view!.center.x + translation.x,y: sender.view!.center.y + translation.y)
  31. sender.setTranslation(CGPointZero,inView: self.view)
  32. self.ifCollided()
  33.  
  34.  
  35. }
  36.  
  37.  
  38. func misleadOne(sender: UIPanGestureRecognizer) {
  39.  
  40. let translation = sender.translationInView(self.view)
  41. sender.view!.center = CGPoint(x: sender.view!.center.x + translation.x,inView: self.view)
  42. self.ifCollided()
  43.  
  44. }
  45.  
  46. func bestival(sender: UIPanGestureRecognizer) {
  47. let translation = sender.translationInView(self.view)
  48. sender.view!.center = CGPoint(x: sender.view!.center.x + translation.x,inView: self.view)
  49. self.ifCollided()
  50.  
  51. }
  52.  
  53. func rosieProject(sender: UIPanGestureRecognizer) {
  54. let translation = sender.translationInView(self.view)
  55. sender.view!.center = CGPoint(x: sender.view!.center.x + translation.x,inView: self.view)
  56. self.ifCollided()
  57.  
  58. }
  59.  
  60. func misleadTwo(sender: UIPanGestureRecognizer) {
  61. let translation = sender.translationInView(self.view)
  62. sender.view!.center = CGPoint(x: sender.view!.center.x + translation.x,inView: self.view)
  63. self.ifCollided()
  64.  
  65. }
  66.  
  67. func misleadThree(sender: UIPanGestureRecognizer) {
  68. let translation = sender.translationInView(self.view)
  69. sender.view!.center = CGPoint(x: sender.view!.center.x + translation.x,inView: self.view)
  70. self.ifCollided()
  71.  
  72. }
  73.  
  74. func misleadFour(sender: UIPanGestureRecognizer) {
  75. let translation = sender.translationInView(self.view)
  76. sender.view!.center = CGPoint(x: sender.view!.center.x + translation.x,inView: self.view)
  77. self.ifCollided()
  78.  
  79. }
  80. func voucher(sender: UIPanGestureRecognizer) {
  81. let translation = sender.translationInView(self.view)
  82. sender.view!.center = CGPoint(x: sender.view!.center.x + translation.x,inView: self.view)
  83. self.ifCollided()
  84.  
  85. }
  86.  
  87. func welsh(sender: UIPanGestureRecognizer) {
  88. let translation = sender.translationInView(self.view)
  89. sender.view!.center = CGPoint(x: sender.view!.center.x + translation.x,inView: self.view)
  90. self.ifCollided()
  91.  
  92. }
  93.  
  94. func hulk(sender: UIPanGestureRecognizer) {
  95. let translation = sender.translationInView(self.view)
  96. sender.view!.center = CGPoint(x: sender.view!.center.x + translation.x,inView: self.view)
  97. self.ifCollided()
  98.  
  99. }
  100.  
  101. func ShowAlertWrong(){
  102.  
  103. let alertController = UIAlertController(title: "Sorry",message: " Guess again!",preferredStyle: .Alert)
  104.  
  105. let okAction = UIAlertAction( title: "Ok",style: UIAlertActionStyle.Default) {
  106. UIAlertAction in
  107.  
  108. self.ukFlag.center = CGPointMake(150,225)
  109. self.movie.center = CGPointMake(150,225)
  110. self.piano.center = CGPointMake(150,225)
  111. self.dance.center = CGPointMake(150,225)
  112. self.paint.center = CGPointMake(150,225)
  113. self.row.center = CGPointMake(150,225)
  114. self.envelope.center = CGPointMake(150,225)
  115. self.dragon.center = CGPointMake(150,225)
  116. self.instagram.center = CGPointMake(150,225)
  117. }
  118.  
  119. let resetAction = UIAlertAction( title: "Reset",style: UIAlertActionStyle.Default) {
  120. UIALertAction in
  121.  
  122. self.ukFlag.center = CGPointMake(150,225)
  123.  
  124. }
  125.  
  126. alertController.addAction(okAction)
  127. alertController.addAction(resetAction)
  128. self.presentViewController(alertController,completion: nil)
  129.  
  130. }
  131.  
  132.  
  133.  
  134.  
  135. func ShowAlertWin(){
  136.  
  137.  
  138.  
  139. let alertController = UIAlertController(title: "Congrats

猜你在找的iOS相关文章