简体   繁体   English

NavigationController不更新导航项

[英]NavigationController doesn't update navigation item

I've just started developing iOS applications. 我刚刚开始开发iOS应用程序。 Now I have such problem. 现在我有这样的问题。 I have NavigationController with TestController class set as root and second controller (class SecondController). 我的NavigationController的TestController类设置为根,第二个控制器(类SecondController)。 I try to redirect TestController to SecondController in method viewDidLoad of TestController with help of method setViewControllers of my NavigationController. 我尝试借助我的NavigationController的setViewControllers方法将TestController重定向到TestController的viewDidLoad方法中的SecondController。 Second controller is instantiated and shown successfully, but NavigationController keeps the old navigation item's title that TestController had. 第二个控制器被实例化并成功显示,但是NavigationController保留了TestController拥有的旧导航项的标题。 I've uploaded test project to cloud: https://cloud.mail.ru/public/D2AC/GBTUboBSo . 我已将测试项目上传到云: https : //cloud.mail.ru/public/D2AC/GBTUboBSo Screen with green background and title "abacaba" must be shown, but instead of that title "Controller 1" of TestController is shown. 必须显示绿色背景的屏幕,标题为“ abacaba”,但显示的是TestController的标题“ Controller 1”。

In real project, i want to use such structure for login screen (check if user is logged in viewdidLoad and if not, redirect him to login screen). 在实际的项目中,我想对登录屏幕使用这种结构(检查用户是否已登录viewdidLoad,否则,将其重定向到登录屏幕)。

Can you help me, what can be a problem? 您能帮我,有什么问题吗?

Hello @Serega you should use this code to redirect to next screen 您好@Serega,您应该使用此代码重定向到下一个屏幕

let nextController = 
     storyboard?.instantiateViewController(withIdentifier: "NextController")
     nextController?.navigationItem.title = "abacaba"
     navigationController?.pushViewController(nextController!, animated: true)

And i will look like this 我会看起来像这样

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM