我的后退按钮出了问题。我有2个VC。每个VC都有自己的后退按钮(它们不是默认值,它们被添加为左栏按钮项。当我从VC1(与Home View Controller链接,未显示)连接到VC2时,我看到VC2但是当我回来时到VC1我看到VC1的导航栏和VC2的视图。我需要做什么? 我也尝试添加func但它没有帮助。
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "comeBack" {
let backVC = self.storyboard?.instantiateViewController(withIdentifier: "CollectionVC") as! RecipeCollectionViewController
self.navigationController?.pushViewController(backVC, animated: true)
}
}
答案 0 :(得分:0)
使用它来推送VC1到VC2
let vc = self.storyboard?.instantiateViewControllerWithIdentifier("VC2") as! VC2
self.navigationController?.pushViewController(vc, animated: true)
并将其用于从VC2到VC1的返回
self.navigationController?.popViewControllerAnimated(true)
答案 1 :(得分:0)
用于弹出特定视图控制器
let viewControllers: [UIViewController] = self.navigationController!.viewControllers
for vc in viewControllers {
if VC is YourViewController {
self.navigationController!.popToViewController(vc, animated: true)
}
}
如果弹出前一个控制器而不是使用
self.navigationController?.popViewControllerAnimated(true)