Embedding View Controller in Tab Bar Controller removes navigation items

这一生的挚爱 提交于 2019-12-11 14:21:12

问题


I have a View Controller which is already embedded in a Navigation Controller as such:

The Table View Controller has a programatically added title and button which work fine:

override func viewWillAppear(_ animated: Bool) {
    navigationItem.title = "The Harrovian"
}

override func viewDidLoad() {
    super.viewDidLoad()

    navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .refresh, target: self, action: #selector(refresh))

I wanted to embed the Table View Controller in a Tab View Controller as such:

Now, however, the title and button of the table view have disappeared. Why? How can I fix it?


回答1:


I know this does not respond to your question entirely, but from what I know, the practice is to first embed the tab bar controller, and then the navigation controller for each tab. That is because every tab is a different view, and you you cannot assign the same navigation to two tabs.

If that would be possible, when you would use the navigation on tab 1, you access the view that is separate from tab 2, and when you switch to tab 2, the same navigation does not apply to the view in tab 2.




回答2:


You are creating the architecture of the wrong app, I would first start by creating the application with the NavBarController, I would use a navigation controller for the rest of the screens, so the navigation does not conflict.

The problem you're presenting is a conflict between the two controllers



来源:https://stackoverflow.com/questions/48756329/embedding-view-controller-in-tab-bar-controller-removes-navigation-items

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!