My app start with a MainViewController that has an UINavigationController. If a show segue to another controller, if the new controller has a UINavigationController it seems to be presented modally, but if I remove the UINavigationController it works fine.
Is this normal iOS behavior?
how can I navigate in the controller if there isn't a UINavigationController anymore?
Every time you segue from your MainViewController (that has a navigationController) to a new ViewController, the new ViewController gets added to the MainViewController's NavigationController's stack.
If you segue to a new NavigationController from your MainViewController you create a new navigation stack and therefore iOS displays it like a modal.
To answer your question, you only need the 1 navigation controller on your MainViewController and all subsequent segues will be pushed onto the stack of that navigation controller. To get navigate back through the navigation stack to the MainViewController, have a look at navController.popViewController(animated: true).
Related
I have been trying to push tabbarcontroller from tabbarcontroller view controller object.attached screenshot please give me some idea.I have tabbarcontroller as initial view and it has navigationcontroller-view controller as child and from view controller I want to push tabbarcontroller.When I push it my second tabbarcontroller tabbar is not visible and i cannot press back button to go back.
use exchange segue in storyboard and you can push the same tabbrcontroller twice.
For example in FirstViewController and I want to push SecondViewController, and I have a navigationController in FirstViewController, I could just push SecondViewController to it right?
Unless SecondViewController has another set of navigation hierarchy, then only it makes sense to create an another navigationController for it?
FirstViewController doesn't have a navigation controller in it; it is in a navigation controller.
A navigation controller is a container. The navigation bar you see at the top belongs to the navigation controller. The content below that belongs to the view controller which is currently at the top of the navigation stack (except the toolbar, if you're showing that).
You can't actually push another navigation controller onto the stack - this raises an exception. So unless you've got a tabbed app structure, most apps will have only one navigation controller.
lol wut?
Right click on the body of the Navigation Controller, drag the blue line to FirstViewController. Choose "Root View Controller" for the popup.
Right click on the body of FirstViewController and drag it to SecondViewController, Choose "push".
Click on the lines between the first and second view controllers, this is a Segue. Give the segue a unqiue Identifier like "firstToSecondSegue".
From within FirstVewController.m you can programmatically push SecondViewController onto the Navigation stack with
[self performSegueWithIdentifier:#"firstToSecondSegue" sender:self];
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.
Let's assume that a first view controller is connected with a UITabBarController and I want to make a push segue to the second view controller from this first view controller.
From my googling, it seems that a modal segue from a view controller connected with a UITabBarController hides the bottom tab bar, while a push segue doesn't.
However, my push segue is also hiding my tab bar in the second view controller. I have overridden prepareForSegue method in the first view controller.
Below are images of my storybard and the simulator. Anyone has an idea why this is the case? Thank you in advance for your helps.
Your trouble is because your tabViewController is embedded in the navigation stack that you initialise with your login screen.
you need to rearrange things so that each of your tab bar controller tabs opens to a new navigation stack.
What I suggest
your loginscreen should navigate to your tab bar controller with a modal/presenting segue, not a push segue. Remove the navController that encloses the loginscreen, you don't need it (well, even if you keep it, don't use a push segue, use a modal segue, and you won't then be referring back to that navController's viewController stack from inside your tab bar).
embed each of the first viewControllers in your tabViewCOntroller inside a separate navController.
Now you can push segue within your tabViewController's tabs.
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")