【Swift 3.0】popViewController出现警告

2018-01-22  本文已影响0人  大山里的村姑

swift3中pop代码出现⚠️,如下图所示


截图

这是因为** popViewController方法默认返回了一个 UIViewController**,所以才会出现这个警告

消除方法

方法一、
_ = self.navigationController?.popViewController(animated: true)

方法二、

//不确定层级
for i in 0..<(self.navigationController?.viewControllers.count)! {

            if self.navigationController?.viewControllers[i].isKind(of: YourViewController.self) == true {
              _ = self.navigationController?.popToViewController(self.navigationController?.viewControllers[i] as! YourViewController, animated: true)
              break
            }

方法三、

//pop返回多个ViewController
let vcCount = self.navigationController?.viewControllers.count
 _ = self.navigationController?.popToViewController((self.navigationController?.viewControllers[vcCount! - 2])!, animated: true)
上一篇下一篇

猜你喜欢

热点阅读