I am trying to build an app with chat options integrated. My conversations view controller(where all the chats of one person are displayed in a tableView with multiple cells) is embedded in a navigation controller as well as the single chat view controller(where you are chatting with only one person).
To go from the conversations view controller to the single chat view controller I am implementing this code:
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)
However, the _vc.title is not showing on the navigation bar. How could I fix this?
_vc.navigationItem.title = "John Smith"
Set title using navigation item.
You need to create an instance of UINavigationController first:
UINavigationController *navController = [self.storyboard instantiateViewControllerWithIdentifier:@"Viewe"];
ViewController2 *vc = (ViewController2 *) [navController topViewController];
navController.modalPresentationStyle = UIModalPresentationFullScreen;
vc.title = @"hello";
and present that navController instance.
There should be a VC that you are presenting first of all and incase you are considering of adding a VC then it goes something like this.
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)
And in the viewDidLoad
of SecViewController give title = "John Smith"
. This will help you add title.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.