Reputation: 3730
So, in this scenario...
Back Button
value to Back.When I build and run, the navigation bar is there in Storyboard C, but no back button in the navigation bar in Storyboard C. In Storyboard A and B, I even put those UITableViews inside a Navigation Controller thinking that to include a back bar, it needs to have come from a navigation controller first, and that didn't work.
When I go to the outlets page of the UINavigationItem, this is what it looks like:
How do I add the back button to Storyboard C?
FYI I'm not that experienced of an iOS developer, so there may be some obvious things that I'm not aware of.
EDIT: I use a show segue
for both A-->C and B-->C segues.
Upvotes: 0
Views: 4373
Reputation: 605
You should setup your views like this:
Embed Navigation Controller
For View A
Embed Navigation Controller
For View B
view A
-> View C
Create Segue from view B
-> View C
You can see that, after you create Segue to View C
, In View C
will appear the navigation bar automatically because you just need to embed navigation controller for the root view (in this case is View A
and View C
)
This is how you can Embed Navigation Controller to a View Controller
After you do like I said. You will get the story board like this:
That's how you need to setup your story board.
So now you have 2 branch of navigation
Hope it helps you
Upvotes: 3
Reputation: 8914
If you're pushing a ViewController "C" on navigation stack then you need to pop that controller on back button tap.
pushing
self.navigationController?.pushViewController(ViewControllerC, animated: true)
poping
self.navigationController?.popViewController(animated: true)
If you're presenting a ViewController "C" then you need to dismiss that controller on back button tap.
presenting
self.presentViewController(ViewControllerC, animated:true, completion:nil)
dismissing
self.dismissViewControllerAnimated(false, completion: nil)
EDIT
you need to add this code like
When going from A -> C, you need to add this in didSelectRowAtIndexPath
method of tableview (on tap of cell), ignore if you are using segue
self.navigationController?.pushViewController(ViewControllerC, animated: true)
When coming back from C -> A, you need to implement bar button action method like this in "C"
in viewDidLoad()
method of view controller "C", add bar button programatically
let backBtn = UIButton(type: .custom)
backBtn.setImage(UIImage(named: "imagename"), for: .normal)
backBtn.frame = CGRect(x: 0, y: 0, width: 30, height: 30)
backBtn.addTarget(self, action: #selector(ViewControllerC.back), for: .touchUpInside)
let item2 = UIBarButtonItem(customView: backBtn)
func back(sender: UIButton){
self.navigationController?.popViewController(animated: true)
}
The same way you can do for View controller B also.
Upvotes: 0
Reputation: 1038
I think your navigation bar gets hidden when come back from another storyboard. In that case you have to show your navigation bar forcefully. In your first view controller in storyboard C. Try the following code:
- (void) viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewWillAppear:animated];
}
swift3
override func viewWillAppear(_ animated: Bool) {
self.navigationController?.setNavigationBarHidden(false, animated: animated)
super.viewWillAppear(animated)
}
Upvotes: 0