【问题标题】:Attempt to present OTPViewController on UIAlertController whose view is not in window尝试在视图不在窗口中的 UIAlertController 上显示 OTPViewController
【发布时间】:2017-05-08 12:20:07
【问题描述】:

我编写了这段代码,以便 viewcontroller 从 loginscreenviewcontroller 更改为 otpviewcontroller。

function createAlert() {
    let alertController = UIAlertController(title: nil, message: "Please wait\n\n", preferredStyle: .alert)
    let spinnerIndicator = UIActivityIndicatorView(activityIndicatorStyle: .whiteLarge)
    spinnerIndicator.center = CGPoint(x: 135.0, y: 65.5)
    spinnerIndicator.color = UIColor.black
    spinnerIndicator.startAnimating()
    self.present(alertController, animated: true, completion: nil)
    Alamofire.request(".....").responseData { response in
       switch response.result {
           case .success:
               self.dismiss(animated: true, completion: nil)
               self.performSegue(withIdentifier: "OTPSegue", sender: self)
       }
    }
}

但它给了我一个错误

Attempt to present <Junkart.OTPViewController: 0x79769c80> on <UIAlertController: 0x79b5fe00> whose view is not in the window hierarchy!

警报控制器确实关闭了,但视图控制器没有变化。

请帮忙。

UPADTE 2 行。因此,我可以更改为另一个 viewController,但警报视图会在新视图控制器动画并占据整个屏幕之前到达顶部。

【问题讨论】:

标签: ios iphone swift


【解决方案1】:

错误非常详尽。

您需要关闭警报视图并然后执行 继续使用新的视图控制器:

alertController.dismiss(animated: true, completion: {
    self.performSegue(withIdentifier: "OTPSegue", sender: self)
}) 

【讨论】:

    【解决方案2】:

    在呈现新视图控制器之前关闭当前视图控制器。那是错误的。改为删除以下行 self.dismiss(animated: true, completion: nil)

    【讨论】:

    • 那我该怎么办?请详细说明
    • 删除以下行:self.dismiss(animated: true, completion: nil)
    猜你喜欢
    • 2019-12-03
    • 1970-01-01
    • 2016-01-06
    • 1970-01-01
    • 2017-04-01
    • 2016-11-29
    • 2023-03-31
    • 2018-06-06
    • 2017-07-27
    相关资源
    最近更新 更多