美文网首页
swift3 popViewController 的改变

swift3 popViewController 的改变

作者: 嗯哼丶傻大个是你 | 来源:发表于2017-01-17 10:27 被阅读0次

    在swift2.x中 有这个方法

    self.navigationController?.popViewController(animated: true)
    

    但是在swift3 就会出现这个警告


    屏幕快照 2017-01-17 10.25.38.png

    解决办法为:

    _ = self.navigationController?.popViewController(animated: true)
    

    Swift 3 大的改动之一就是所有带有返回值的函数如果没有变量去接收返回值,就会报warning。
    popViewController和popToRootViewController基本上人人都用,但是有多少人知道这两个函数其实是有返回值的。
    看一下官方的解释吧

    open func popViewController(animated: Bool) -> UIViewController? // Returns the popped controller.  
    open func popToViewController(_ viewController: UIViewController, animated: Bool) -> [UIViewController]?   
    // 官方解释
    // Pops view controllers until the one specified is on top. Returns the popped controllers.  
    

    相关文章

      网友评论

          本文标题:swift3 popViewController 的改变

          本文链接:https://www.haomeiwen.com/subject/hbrmbttx.html