how could i push view controller to navigation controller - ios

I want to go from my Login Page to the MainMenuViewController but the MainMenuViewController is a navigation Controller.
I searched for a while but it still doesn't work correctly. Could anyone tell me what's going on?
My code:
MainMenuViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier: #"MainMenuViewController"];
[self presentViewController:vc animated:YES completion:nil];

What exactly is the issue? This will present a view controller that you choose, if you want to get the navigation view to show up correctly you will want to transition not to the MainMenuViewController, but the root view controller for that. When you look at the storyboard, you can see the navigation controller that segues to the MainMenuViewController, present that view controller instead of the MainMenuViewController.

Set the storyboard ID for your navigation controller and write the below code in the function.
UINavigationController * navigationController = [[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"SecondNavigationController"];
[self presentViewController:navigationController animated:YES completion:nil];
Hope this helps. :)

Related

Navigation from one view to another view in IOS (objective c)

I am new in IOS. I am confused in navigation.I have looked 3,4 methods to navigate from one view to another view controller.
First
DashboardViewController *dashboard = [self.storyboard instantiateViewControllerWithIdentifier:#"DashboardViewController"];
[self.navigationController pushViewController:dashboard animated:YES];
Second :- Using push segue on clicking button.
Third :- I'm not clear for it, That is array of view controller. In which we get the view controller and then navigate.
Fourth:-
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"Main"
bundle:nil];
UserDashboardViewController *users =
[storyboard instantiateViewControllerWithIdentifier:#"UserDashboardViewController"];
[self presentViewController:users
animated:YES
completion:nil];
I am confused which is best way for navigation, and most important how to navigate using array of view controllers. Please help me, Thanks.
This is the best way in my point of view.

Push to a UIViewController from a presentViewController

I want to push to a new viewcontroller from a presented viewcontroller. I don't want to dismiss the presented viewcontroller. I want the new viewcontroller to come over the presented viewcontroller.
Can anybody tell me how to do that.
You do not push form the presented controller so the best option is
First you have to dismiss the controller without animation and then in the method of -(void)viewWillApper you can easly push to the controller where you want to push.
You can do by using UINavigationController like
UINavigationController *vcObject = [[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"YourViewController"];
[self.navigationController presentViewController:vcObject animated:YES completion:NULL];
Now you can easily push or pop to other ViewController like you want.Thankyou
Open your modalView controller as a new rootViewController :
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:nextViewController];
[self.navigationController presentViewController: navController animated:YES completion:nil]

Call another class in IOS

I'm new on IOS platform and after study a little about how does it works, i had one doubt about how to call a new class/view and overlay the current view when a button is pressed. In android i do:
Intent intent = new Intent(a.class, b.class);
startActivity(intent);
Searching on internet, i noticed that i have to use navigation bars to do it. I start an app with tab bar controller and putted a navigation controller. I used the code below:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
UIViewController *myController = [storyboard instantiateViewControllerWithIdentifier:#"Dicas"];
[self.navigationController pushViewController: myController animated:YES];
and the return:
There is a way to overlay the current view? I always have to use navigation bars to call another class (use bottom e upper controllers will make my app ugly)?
To hide the navigation bar:
[[self navigationController] setNavigationBarHidden:YES animated:YES];
To hide tab bar:
yourViewController.hidesBottomBarWhenPushed = YES;
You can also call another viewController by using presentViewController function of a viewController class.
[self presentViewController: myController animated:YES completion:nil];
As you said u want to overlay your current view so not sure but You can show your view controller using model view like this
yourViewController *secView = [[YourViewController alloc] initWithNibName:#"YourViewController" bundle:nil];
[secView setModalPresentationStyle:UIModalPresentationPageSheet];//u can use different UIModalPresentationStyle
[secView setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self.navigationController presentViewController:secView animated:YES completion:nil];
Above one will show your view controller over existing view controller, once presented you need to make provision to dismiss this modal view.
Simple way to present new class or ViewController like this..
ViewController *view = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewController"];
[self presentViewController:view animated:YES completion:nil];

Black screen in navigation controller

I am unable to see the view controller in my navigation controller.
Currently a user saves some information and I want to push them to the start of the app again.
I am doing this programatically.
Currently for what I have below, the navigation controller is displayed but the view controller is not.
SubclassConfigViewController *nextViewController = [[SubclassConfigViewController alloc]initWithNibName:nil bundle:nil];
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:nextViewController];
[self presentViewController:navController animated:YES completion:nil];
Any help anyone can provide is greatly appreciated! :-)
With a storyboard you should be using this:
SubclassConfigViewController *nextViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"Next"];
Make sure you give the controller an identifier in IB, and pass that string in the method.

how to transit to a view controller

I made a view controller A in storyboard and linked with other view controller. Now I have another view controller B and I want to write a method that can transit from B to A. How can I do this?
There is a segue to controller A in storyboard.
And controller B is loaded from another view I created programmatically so I can't set a segue in storyboard.
Since you are using storyboard. This is more accurate, try this:
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:#"YOUR VIEW CONTROLLER"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];
But be sure to name your view's identifier otherwise it will crash and wont work.
Then when you want to dimiss the view:
[self dismissModalViewControllerAnimated:YES];

Resources