【问题标题】:UIAlertController Error When called in a modal presented view controller in swiftUIAlertController 错误当在 swift 中以模态呈现的视图控制器中调用时
【发布时间】:2015-08-20 07:02:13
【问题描述】:

我有一个模态显示的视图控制器,当我运行 UIAlertController 时,不断收到错误消息。我该如何解决这个问题。

警报由一个按钮触发,该按钮检查文本字段是否为空。

@IBAction func registerAction(sender: AnyObject) {
if(userEmail.isEmpty){
        alertMessage("Fields Are Empty")
    }
}



func alertMessage(userMessage:String){  
    var myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert)
    let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)
    myAlert.addAction(okAction)
    self.presentViewController(myAlert, animated: true, completion: nil)
}

运行警报时出错

Warning: Attempt to present <UIAlertController: 0x7f9bbb9060d0>  on <AlertApp.CustomSignupVC: 0x7f9bb94accb0> which is already presenting <UIAlertController: 0x7f9bbb926660>

【问题讨论】:

  • 它没有连接到一个segue

标签: ios swift


【解决方案1】:

尝试将其添加到主操作队列中。

dispatch_async(dispatch_get_main_queue()) {
    self.presentViewController(myAlert, animated: true, completion: nil)
}

检查这个相关问题:Presenting a view controller modally from an action sheet's delegate in iOS8 - iOS10

【讨论】:

  • @MugunthanBalakrishnan 随时欢迎 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-20
  • 1970-01-01
  • 1970-01-01
  • 2016-02-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多