Change back button label in navigation bar using Storyboard? - ios

I have a navigation controller, with 3 view controllers.
Nav Ctrller -> VC1 -> VC2 -> VC3
Say I want the 'Back' button on VC2 and VC3 to read 'Previous' instead. In VC1, I selected/highlighted the nav bar item from Storyboard and changed the Back Button property to 'Previous'.
Now VC2 back button says 'Previous', but the back button on VC3 still says 'Back'. I thought I need to make the same change for nav bar item in VC2, but there is no nav bar item to select. I guess nav bar item shows up only in root VC?
Currently I am changing the back button label on VC3 by code. Is there no option to change the back button label on VC3 using Storyboard?
Thanks.

Drag a navigation item to your VC3

Related

Application with tab bar and navigation bar in all controllers

I have a problem with adding tab bar to all the controllers in the screen, it's only shown in the controllers that is directly connected to the tab bar. How can I show It in all screens?
I found the answer, my problem was I didn't add navigation controller for each tab bar item, I made only one navigation controller that's why the tab bar didn't appear.
The right sequence is:
TabBarItem1 -> NavController1 -> ViewController1 -> ViewController2
TabBarItem2 -> NavController2 -> ViewController1 -> ViewController2

Swift: present view controller in same context as other view controllers?

Ok, I have an issue that I cant understand trying to present a view controller (the same instance every time, just like other tab item VCs) from an overall tab bar controller VC. My tab bar controller VC has 3 view controllers that it is connected to via storyboard, so 3 tab bar items appear on the tab bar. When the selectedIndex is changed, these view controllers just appear right there below the subviews of the Tab Bar Controller VC.
These subviews that should always be on top are the nav bar at the top and tab bar at bottom:
And this is great for those 3 view controllers. Problem is I need to access 1 instance of ANOTHER view controller that is NOT shown in the tab bar buttons via a button in the nav bar here.
My problem is no matter how I present it, this VC always pops OVER the tab bar controller VC, covering the tab bar and nav bar.
here I make sure only 1 instance is made:
if podcastVC == nil {
//print("IT IS NIL")
let storyboard = UIStoryboard(name: "Main", bundle: nil)
podcastVC = storyboard.instantiateViewController(withIdentifier: "podcast") as! PodcastViewController
//*NOTE: have to set other vars too, this is temp
podcastVC.urlStr = currentTrackUrl!
podcastVC.originalUrl = currentTrackUrl!
AudioPlayerManager.shared.play(urlString: podcastVC.urlStr)
}
self.show(podcastVC, sender: self)
podcastVC.modalPresentationStyle = .currentContext
podcastVC.definesPresentationContext = false
[1]: https://i.stack.imgur.com/1d6MZ.png
as shown by Swift: How to return to the same instance of my UIViewController
How can I make that VC present in the same context as the tab bar items? I have tried setting the layer of the nav bar to a z position much higher (like 10) but nothing works. What is wrong?
Modal view :
Can works for all view controllers
Is over all other view and need to be pop programatically (adding a button back manually for example)
Push View :
Only works in navigation controllers
Add automatically a back button in the navigationController
you should push VC and it will keep tabbar and nav
you can change modal present style

Navigation controller with tab bar controller of navigation controller

I have a navigation controller, and its root view controller is a tab bar controller. In this tab bar controller I have two view controllers like this:
In the tab bar controller I have a custom navigation bar.
When I click the first item in tab bar, the navigation bar looks good
but when I click the second, I have a problem: below the navigation bar there is another navigation bar with red color.
Can some explain this for me?
If you don't want navigation bar of first navigation controller then from the interface builder (storyboard) select your root navigation controller (i.e. navigationcontroller that's embed with tabbarcontroller) and from attribute inspector uncheck shows navigation bar under Navigation controller! This will hide navigation bar for root navigation view controller!!
In your case you should hide and show navigation bar in viewWillDisAppear and viewWillAppear something like,
In viewWillAppear
self.navigationController.navigationBar.hidden = NO;
In viewWillDisAppear
self.navigationController.navigationBar.hidden = YES;
Do above things for your both viewcontroller of your tabbarcontroller!!
You can do navigationController.navigationBarHidden = true on the root navigation controller, or the child whatever suits you.
But the better will be if you use only one UINavigationController, and IMO navigationController of UITabBarController only.

Navigation controller with tab bar controller?

I have a tableViewController embedded in my tab bar controller. When a cell is tapped, a segue is launched to another view controller to show the details of that object. However, the Back button is not appearing in the viewDetail. I tried embedding the view into a separate Navigation Controller but that didn't change anything. What am I doing wrong? I currently have Tab Bar Controller -> tableView -> Navigation Controller -> viewDetail (need Back button here to return to tableView).
Here's what I have right now:
Thanks!!
Each UIViewController in UITabBarController could be embedded in an UINavigationController at your convenience, that way you'll be able to use all of the features that you need.
Basically, you need to select the tableViewController, click on Editor menu item, select Embed in and click on Navigation Controller, ta daa.
You can show or hide Navigation Bar if you need it using Interface Builder or programmatically in your Detail viewController as follows:
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBarHidden = true
// Do stuff
}
Set NavigationController to TabBarController, then set NavigationController's rootViewController to TableViewController.
You just have the organization wrong. Currently you have Tab Bar Controller -> tableView -> Navigation Controller -> viewDetail. It should be Tab Bar -> tableview -> View detail. Navigation should be separate pointing to table view. Nothing should be pointing to navigation. It should just point to tableview
It should look something like the above picture

How to dismiss a PopOver after another BarButtonItem has been pressed

I have a ViewController that contains a navigation bar. In this navigation bar, there are 2 UIBarButtonItem: A and B.
When A is pressed, another ViewController is displayed as a PopOver (segue present as popover).
If I press anywhere on the screen, the popover is dismissed.
The problem is that if I press on B (the other UIBarButtonItem) the PopOver is not dismissed...
What should I do to automatically dismiss opened popovers when bar buttons from the navigation bar are pressed?

Resources