ios - 返回按钮有问题

标签 ios swift view uiviewcontroller

我的后退按钮出现了奇怪的问题。我有2个VC。每个 VC 都有自己的后退按钮(它们不是默认的,它们被添加为左栏按钮项目。当我从 VC1(与主视图 Controller 链接,未显示)到 VC2 时,我看到 VC2,但当我回来时到 VC1 我看到 VC1 的导航栏和 VC2 的 View ,我需要做什么? 我也尝试添加 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)
    }
}

enter image description here

enter image description here

enter image description here

enter image description here

最佳答案

用它来将 VC1 推送到 VC2

let vc = self.storyboard?.instantiateViewControllerWithIdentifier("VC2") as! VC2
self.navigationController?.pushViewController(vc, animated: true)

并使用它从 VC2 返回到 VC1

self.navigationController?.popViewControllerAnimated(true) 

关于ios - 返回按钮有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42670289/

相关文章:

objective-c - 从 NSDictionary 对象中计算货币

ios - 替换 CGRectMake 的正则表达式

ios - 我该怎么做才能在 View Controller 中访问此 TableView ?

javascript - 单页面主干应用程序中 View 之间的转换

iOS - 从容器内嵌入的 UITableView 检索父 View 中的单元格标题

ios - 使用 sprites velocity (swift) flappy bird 游戏旋转 Sprite

java - 安卓查看错误

java - MVC : How to properly create a view for an unknown model

ios - 更新约束

swift - ImplicitlyUnwrappedOptional in init vs later