问题描述
问题storyboard跳转到代码界面,UINavigationController在storyboard界面显示,代码界面不显示
代码我是在AppDelegate里增加UINavigationController的
//AppDelegate.swiftlet storyboard = UIStoryboard(name:'Main',bundle:nil)let viewController = storyboard.instantiateViewController(withIdentifier: 'LoginViewController')//let viewController = LoginViewController()let nav = UINavigationController(rootViewController: viewController)self.window?.rootViewController = viewControllerself.window?.addSubview(nav.view)self.window?.makeKeyAndVisible()//统一导航条样式let textAttributes = [NSFontAttributeName: UIFont.systemFont(ofSize: 19.0), NSForegroundColorAttributeName: UIColor.white]UINavigationBar.appearance().titleTextAttributes = textAttributesUINavigationBar.appearance().tintColor = UIColor.whiteUINavigationBar.appearance().barTintColor = UIColor.red
在storyboard界面通过该方式跳转
//LoginViewController.swiftlet chatListView = SingleChatListViewController()self.present(chatListView, animated: true, completion: nil)结果
这个首页是正常的
这个就不对了
问题解答
回答1:self.present(chatListView, animated: true, completion: nil)替换成self.navigationController?.pushViewController(chatListView , animated: true)就ok了你是用present显示出来的,跟nav显示的页面不在一个逻辑的话可以使用这种方式
回答2:虽然没用过swift,但是你api貌似用错了
//在storyboard界面通过该方式跳转//LoginViewController.swiftlet chatListView = SingleChatListViewController()self.present(chatListView, animated: true, completion: nil)
self.navigationViewController 的是用push跳转的,你的present是另外一种跳转方式