假设需要返回到的控制器为firstViewController
代码如下:
for i in 0..<(self.navigationController?.viewControllers.count)! {
if self.navigationController?.viewControllers[i].isKindOfClass(firstViewController) == true {
_ = self.navigationController?.popToViewController(self.navigationController?.viewControllers[i] as! firstViewController, animated: true)
break
}
}
在相应的方法中这样写就可以返回到指定的页面了