【问题标题】:Attempt to present <app.TabController> on <app.ViewController> which is already presenting <UIAlertController> in swift尝试在 <app.ViewController> 上呈现 <app.TabController> ,它已经在 swift 中呈现 <UIAlertController>
【发布时间】:2016-02-18 23:49:20
【问题描述】:

好的,所以我添加了一个please wait 弹出窗口,用于在我的 ios 应用中花费比平时更长的操作。

我有一个从 ViewController 到 TabController 的 segue,当我像这样调用它时:

self.performSegueWithIdentifier("openMainApp", sender: self)

一切正常。

但是当我将它包围时:

let alert = UIAlertController(title: nil, message: "Please wait...", preferredStyle: .Alert)

alert.view.tintColor = UIColor.blackColor()
let loadingIndicator: UIActivityIndicatorView = UIActivityIndicatorView(frame: CGRectMake(10, 5, 50, 50)) as UIActivityIndicatorView
loadingIndicator.hidesWhenStopped = true
loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray
loadingIndicator.startAnimating();

alert.view.addSubview(loadingIndicator)
presentViewController(alert, animated: true, completion: nil)

    self.performSegueWithIdentifier("openMainApp", sender: self)

dismissViewControllerAnimated(false, completion: nil)

然后我收到警告:

Warning: Attempt to present <app.TabController: 0x7ff6dc00bd40>  
on <app.ViewController: 0x7ff6d9cf6600> which is already presenting 
<UIAlertController: 0x7ff6d9d78530>

如何跳过此警告?

【问题讨论】:

    标签: ios swift uiviewcontroller uialertcontroller


    【解决方案1】:

    虽然此警告的来源对我来说仍然是个谜,但有一种方法可以跳过该警告。

    1. 从情节提要中删除转场
    2. 为您的视图控制器提供故事板 ID,例如:

    3. 替换 self.performSegueWithIdentifier("openMainApp", sender: self)

      let viewController: UIViewController =
        self.storyboard!.instantiateViewControllerWithIdentifier("MainScene")
      self.presentViewController(viewController, animated: true, completion: nil)
      

    【讨论】:

      【解决方案2】:

      Idan 的回答可能有效,但我建议使用 MBProgressHudSVProgressHud 之类的内容。当您在关闭警报控制器之前执行 segue 时,看起来 swift 不喜欢它,因为它是它自己的视图控制器。 Here 是如何实现 MBProgressHud。 Here 是如何实现 SVProgressHud。如果您不想使用 CocoaPods,只需下载 zip 文件并将 .m 和 .h 文件添加到您的项目中即可。

      【讨论】:

        猜你喜欢
        • 2016-10-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-05-24
        • 1970-01-01
        • 2021-11-05
        • 1970-01-01
        相关资源
        最近更新 更多