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

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.

Related

Navigation controller dont work

I have three view controllers in my storyboard.
In second controller I have navigation controller embeded. Second controller is connected to third with segue.
From first view controller, I call second one by presentViewController. In presented view controller I press a button that trigger a segue. What I expect is to see navigation controller in second and third view controller, but third viewcontroller is also shows from bottom to top with out navigation controller.
How to make nav controller visible in second and third view controller ?
Select the segue
between your secondView and thirdView in your StoryBoard
and look it has this settings:
Take care the identifier is what you want, the key here is the kind type of segue

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

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

PerformSeque from button

Currently I'm writing a iOS app with Xamarin.iOS and I wrote a custom UITabbarController named BaseTabbarController. In this ViewController I made a centered raised UIButton over the TabBar to achieve something like this:
So this means that in my BaseTabbarController there is a onClick delegate for my button. When the button is pressed I would like to performSeque(push) to a new ViewController. The following code gives me the error: "Could not find a navigation controller for segue 'searchSegue'. Push segues can only be used when the source conroller is managed by an instance of UINavigationController".
So what should I do right now? I'm not sure how to fix this..
My storyboard looks like this and I'm talking about the second row.
If the button which causes push segue is on tabbar then you an not perform push segue on it because tabbar controller is supposed to be a rootview controller and to have push segue your controller must have navigation controller as container.
For example MyViewController is controller for view A and OneMoreViewController is controller for view B now you want to call view B from view A then embed view A inside navigation controller
// Programmatically
MyViewController *vc= [MyViewController alloc] init];
UINavigationController *nav = [UINavigationController alloc] initWithRootViewController: vc];
If you want to add that View A in tabbar then add nav object inside tabbar.
Now you can call viewB from view A using Push segue.
// and if your using storyboard then
Select the view which you want to embed inside navigationcontroller and choose Editor\Embed In\Navigation Controller from menu bar. that's it.
You've got a push segue hooked up from your tab bar controller to the navigation controller on the second row -- that's not right. That should be a relationship segue (i.e. one of the tab bar controller's view controllers, a second tab).
After Edit:
To be able to push that controller from any other controller on screen, all the base controllers in each tab will have to be a navigation controller. As long as that's true, you should be able to do this. The basic procedure would be to find out which navigation controller's stack is onscreen (with the tab bar controller's selectedViewController method), and perform a push in code from that navigation controller, using pushViewController:animated:. In the storyboard, you would want to have the controller you're pushing be disconnected from everything (no segues), and have an identifier, so you can get it from the storyboard to do the push.

IOS View controller communicate

Hi I have a view controller A that deal with view A, and a view controller B for view B. Now to go to view B when user click a button in view A?
You can create a UINavigationController , the NavigationController's rootViewController is view A . When the user clicks the button at view A, push View controller B onto the NavigationController. use this method: pushViewController:
good luck with you!
Push View Controller A onto a UINavigationController to begin with. When the user clicks on the button in view A, push View Controller B onto the navigation controller.
Create an IBAction method for the button, initialize your view B, and push it onto the view stack.
This is very well documented in the documentation. You should check it out!
If you are using Storyboard this becomes much much easier. Just select the scene for View A in the Storyboard view, then on the Menu bar, Click Editor->Embed In->Navigation Controller. This will add the Nav Controller automagically and make View A the Root View Controller. Then it is just a matter of wiring up a Segue from View A to View B.

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