簡體   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