繁体   English   中英

在导航控制器之间导航时导航栏不显示标题

[英]Navigation Bar not showing Title when navigating between navigation controllers

我正在尝试构建一个集成了聊天选项的应用程序。 我的对话视图控制器(其中一个人的所有聊天都显示在具有多个单元格的 tableView 中)嵌入在导航 controller 以及单个聊天视图控制器(您只与一个人聊天)中。

从对话视图 controller 到 go 到单个聊天视图 controller 我正在实现此代码:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let _vc = storyboard.instantiateViewController(withIdentifier: "myNavigationController") as! UINavigationController
        _vc.title = "John Smith"
        _vc.modalPresentationStyle = .fullScreen
        present(_vc, animated: true, completion: nil)

但是,_vc.title 没有显示在导航栏上。 我该如何解决这个问题?

_vc.navigationItem.title = "John Smith"

使用导航项设置标题。

您需要先创建一个 UINavigationController 的实例:

 UINavigationController *navController = [self.storyboard instantiateViewControllerWithIdentifier:@"Viewe"];
ViewController2 *vc = (ViewController2 *) [navController topViewController];

navController.modalPresentationStyle = UIModalPresentationFullScreen;

vc.title = @"hello";

并呈现该 navController 实例。

首先应该有一个 VC,如果你正在考虑添加一个 VC,那么它会像这样。

在 Swift 中:


 let sb = UIStoryboard(name: "Main", bundle: nil)
 guard let vc = sb.instantiateViewController(withIdentifier: "SecViewController") as? SecViewController else { return }
 let navController = UINavigationController(rootViewController: vc)
 navigationController?.modalPresentationStyle = .fullScreen
 present(navController, animated: true)

并在 SecViewController 的viewDidLoad中给出title = "John Smith" 这将帮助您添加标题。

暂无
暂无

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

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