美文网首页
Swift 解决Pushing the same view co

Swift 解决Pushing the same view co

作者: MambaHJ | 来源:发表于2018-03-28 00:18 被阅读114次
  • bug: Pushing the same view controller instance more than once is not supported
    这个bug是由于在使用Navigation Controller时一个界面还未被释放就再次被push,查了Stack Overflow后找到了合适的解决方法:

在要push的地方加一个判断: 要push的ViewController 是否在navigation的顶部

  • 调用isKind(of: )方法
  • TableViewController.self换成你自己定义的tableview
  • wordC换成你自己要push的界面

原文是oc代码,于是我修改成了swift代码:

 if (self.navigationController?.topViewController?.isKind(of: TableViewController.self))!{
                self.navigationController?.pushViewController(wordC, animated: true)
            }else{
                NSLog("此处可能会报错")
            }

下面是原文的oc代码:

if(![self.navigationController.topViewController isKindOfClass:[YOURCLASS class]]) {
}

最后贴个Stack Overflow地址:
解决Pushing the same view controller instance more than once is not supported

相关文章

网友评论

      本文标题:Swift 解决Pushing the same view co

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