Storyboard - go back to tab bar controller from modal view controller - ios

I have a tab bar controlled application.
And I have a flow that goes something like this:-
Tab 1 View Controller (initial view controller) - "presented modally" View controller - "pushed" View Controller 2 - "pushed" View Controller 3 - "presented modally" View Controller 4
Basically, it is Modal - Push - Push - Modal
Now, I want to go back to Tab 1 View Controller(initial view controller) from View Controller 4 (that was presented modally).
View controller 4 should have a "back button" which when pressed will lead me back to Tab 1 View Controller.
How do I do that? I tried:-
Creating a whole new UIWindow and placed things back. Problem is the back button which I placed on View Controller 4 comes back on Tab 1 View Controller. Weird. Tried removing it with various methods, didn't go away.
Use the popToViewController method, but the navigation controller is different because of last modal view controller.
Any clues on how to solve this?

Okay so I solved it. I needed to climb back down the ladder.
Dismiss self.navigationController.presentingViewController.presentingViewController, which was pointing to UITabBarController, where self.navigationController is from View Controller no. 4 (the last modal view controller).

You should try this on the button that leads to the first tab view controller
UIStoryboard *mySB = [UIStoryboard storyboardWithName:#"[StoryBoardFileName]" bundle:nil];
UIViewController *vc = [mySB instantiateViewControllerWithIdentifier:#"[ViewControllerIdentifier]"];
[self presentViewController:vc animated:YES completion:nil];
hope it helps

Related

Why is the tab bar not appearing throughout the app?

I have implemented a tab bar, but as I go through the app I am not seeing the tab bar. It disappears after I go to a certain page. This is how I implemented it. I have a tab bar connected to a vc which is embedded inside a navigation controller. So the hierarchy looks like this.
----UITabBarController
-------UINavigationController
-----------ViewController 1 with button to view controller 2 (I can see the tab bar)
----------------View Controller 2 (I can't see the tab bar)
It sounds like the segue that you get from view controller 1 to view controller 2 is a "present" segue, rather than a "push" segue. (If I recall correctly, Apple removed "push" segues from Storyboards recently.) Sadly, "present"ed view controllers appear in front of the navigation controller.
In order to do a "push" segue, you have to do it in code, e.g.:
- (IBAction)buttonTapped: (id)sender
{
ViewController2 *viewController = ...
[self.navigationController pushViewController:viewController];
}
i think you missed to initial tab bar as initial view controller

How to navigate a child view controller from other child view controller in objective c

I want to navigate to a view controller from another controller. Both view controllers are child of root view controller of navigation view controller. Now I want to navigate to a second view controller from the first view controller and same as first view controller from second view controller using navigation view controller. How to do that?
The Storyboard image is as follows :
you can just drag a segue from child1's button to child2, and child2's button to child1, though the storyboard will look ugly, but it works. or you can just use
[self.navigationController pushViewController:child2 animated:YES];
You can setup NavigationController with rootViewController is Controller1
when navigation to Controller2 (from Viewcontroller1) just push viewController2 to navigation controller.
when navigation to Controller1 (from Viewcontroller2) just pop viewController2 from navigation controller (or pop to viewController1).
Make another segue from first View Controller to Second View Controller & give it Push navigation.Also give identifier to segue like 'ABCSegue'. Then On the action of Button write
[self performSegueWithIdentifier:#"ABCSegue" sender:nil];
Do same for navigate from second view controller to first view controller.
Hope this will help you.

Go back from pushed navigation controller

Screenshot below is of a sample xCode Master Detail project. I put a Delete button on the Detail scene's navigation bar.
When I tap this button, I want the Detail view to close and go back to the Master view. This is the code:
-(IBAction)delete:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
It does not work. The default back button on the navigation bar does. How do you close a view that has been pushed from accessory action?
Note, the above storyboard comes with the Master-Detail Application template:
You can always get back to the root by calling
[self.navigationController popToRootViewControllerAnimated:YES];
In your case, the problem is that you are pushing second navigation controller onto the navigation stack and it looks like this:
navigation controller -> table view controller -> navigation controller -> detail view controller
You should directly segue from the table view to the detail view so the navigation stack looks like:
navigation controller -> table view controller -> detail view controller

iOS - navigation controller back button

I'm developing an iPad App using storyboards. In this app when the user click on "preferences" appear a modal View. One button of this view send the user to another View Controller (but this view has an action bar to go back to his root view controller), but when user taps the action bar back button nothing happen (it's called navigationController popViewControllerAnimated), the user continue in the same view.
Can anyone help me??
Thanks.
UPDATE:
The code to handle the back button:
- (IBAction)btnBackTapped:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
I'm using Segue (from storyboard) to call this View Controller:
When the user click on "Meus Favoritos"
They will be redirect to this page:
The segue is with a Modal (from image one to two)...
When you are presenting a View Controller modally, it is likely not within a Navigation Controller, so probably the reference to navigationController in your code is nil, can you check that?
If you are presenting your View Controller modally this will work instead
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
However, if you actually want to use a Navigation Controller, you should embed the View Controller that is presenting the Preferences View Controller in a Navigation Controller and present the Preferences View Controller with a show segue instead of a modal one.

UINavigationController shows black screen after pushing a view

I have a storyboard application with a navigation controller an two views controllers ('A', 'B').
In the Storyboard file:
Navigationcontroller is the initial view controller. view controller 'A' is connected to the Navigationcontroller as rootcontroller. View controller 'B' is in storyboard but not connected to any view controller.
when i programmatically try to push view controller 'B' onto the navigationcontroller from inside view controller 'A' with:
B *controllerB = [[B alloc] init];
[self.navigationController pushViewController:controllerB animated:YES];
all i get is a transition to a black screen.
i checked the navigationController property in view controller A at runtime and it´s not nil.
I do not instantiate the navigationController by myself, I let storyboard do the work (maybe that´s the problem). But I think it should be possible to "manually" push view controller to a navigation controller created by storyboard.
When I connect a segue from a button to 'B' in storyboard everything works fine.
Only programmatically it does not work, only shows a black screen inside the navigationcontroller.
Maybe someone could help me with this issue.
I haven't used storyboards yet so this answer is from a glance at the docs. It looks like you can't alloc/init a view controller from a storyboard. You need to use the instantiateViewControllerWithIdentifier: method of your UIStoryboard instance and then you can push the controller.
The accepted answer didn't work for me. I was already using instantiateViewControllerWithIdentifier to navigate to view controller in different storyboard. I am using xcode7.2 and Swift.
I am navigating from storyboard1, some view controller's button action.
Destination is to initial Navigation controller of Storyboard2.
Still I get black screen.
The problem was storyboard2's Navigation controller linked to 1st view controller was linked via show.
Solution:
Delete the link between Nav controller and 1st view controller. Now link it using root view controller. (Ctrl+Click on Navigation controller and drag it to the View controller and Select the option "root view controller")

Resources