I have a ViewController which is inside NavigationController, lets call this VC ABCViewController. Now i have created a story board which is not inside the NavigationController. Now i want to push the storyboard inside the NavigationController when some button is pressed on the ABCViewController.
any Help.
First load your storyboard:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MyStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"myVC"];
Then Push the wanted UIViewController to your UINavigationController
[self.navigationController pushViewController:vc animated:YES]
Related
I created a SingleView application then use "Embed In Navigation Controller" to get a navigation control.
when push a controller, the viewcontroller's backgroundColor is black.
i know use this code :
UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];//UIStoryboard(name: "Main", bundle:nil)
UIViewController *roomController = [storyBoard instantiateViewControllerWithIdentifier:#"controlerID"];
but what's the reason ?
and if i don't want to use the storyboard completely ,only use this code
UIViewController *roomController = [[UIViewController alloc]init];
what can i do? is only set the viewcontroller's backgroundColor?
You need to use the instantiateViewControllerWithIdentifier: method of your UIStoryboard instance and then you can push the controller.
UIStoryboard *storyboard =[UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *roomController = [storyboard instantiateViewControllerWithIdentifier:#"controlerID"];
[self.navigationController pushViewController: roomController animated:YES];
// if You make controller with out storyboard Than change You view color
UIViewController *roomController = [[UIViewController alloc]init];
[self.navigationController pushViewController: roomController animated:YES];
- (void)viewDidLoad
{
self.view.backgroundColor =[UIColor whiteColor];
}
I have two profile in my app. So after some initial profile setup, my app will start with different screens (firstVC or SecondVC).
So based on the initial (Consider Appdelegate :didfinish Method) setup, i wish to select "sw_front" to be firstVC or secondVC.
Every time firstVC is loaded first. If i wish to open SecondVC first, i tried is very simlpe code in viewWillAppear Method, may be incorrect:
UIViewController * sec = [self.storyboard instantiateViewControllerWithIdentifier:#"SecondID"];
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:sec];
[self.revealViewController pushFrontViewController:nav animated:YES];
The issue is app directly enters firstVC, but I want it to enter directly in FirstVC or SecondVC, when needed.
Thanks, any help appreciated :)
May be you are coding wrong.Try below code when you are pushing.
UIStoryboard *storyboard = nil;
storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
SWRevealViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"SecondID"];
[self.navigationController pushViewController:vc animated:YES];
I want to add a navigationcontroller to an existing viewcontroller which is created using storyboard, i have embed it in a navigation controller, but the code for navigating (shown below) is not working even after embed in the navigation controller:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
EditProfileViewController *nextViewController = [storyboard instantiateViewControllerWithIdentifier:#"EPVController"];
[self.navigationController pushViewController:nextViewController animated:YES];
When i have tried to log self.navigationController, it shows null.
Update: It is fine when i am trying with presentViewcontroller , but i
want to push the viewcontroller with navigationController.
I am struggling with this for two days,Please help.
If self is a subclass of UINavigationController, you do not need to refer to the navigationController property. (Note that this won't work if EditProfileViewController is also a subclass of UINavigationController, as you can't push a UINavigationController inside a UINavigationController).
EditProfileViewController *nextViewController = [storyboard instantiateViewControllerWithIdentifier:#"EPVController"];
[self pushViewController:nextViewController animated:YES];
Otherwise, if you don't have a pre-existing navigation controller
EditProfileViewController *nextViewController = [storyboard instantiateViewControllerWithIdentifier:#"EPVController"];
[self presentViewController:nextViewController animated:YES completion:nil];
I used code from this question Display UIViewController as Popup in iPhone it is working fine but I don't want to use segue or I can say I can't use segue because all the code is created programmatically, so I cant set segue on button.
I used this code but it didn't work
- (IBAction)open:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *newVC = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:#"Second"];
[ViewController setPresentationStyleForSelfController:self presentingController:newVC];
[self.navigationController pushViewController:newVC animated:YES];
}
Edit 1:
View after popup
You should check if this VC self.navigationController is not nil. and i think you want to presentViewController: not pushViewController:...
I am really confused about the relationship between storyboards and pushing to views programmatically.
I am using SWRevealViewController to display a menu of items.
If I push to the storyboard using
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
PhotosViewController *controller = [storyboard instantiateViewControllerWithIdentifier:#"PhotosViewController"];
[self presentModalViewController:controller animated:YES];
[self.navigationController pushViewController:controller animated:YES];
All of the information in my storyboard is displayed but there is no "back" button to the SWRevealViewController.
If I push to the view controller using
PhotosViewController *frontViewController = [[StreamScreen alloc] init];
newFrontController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
Then I can view everything that I have added programmatically but nothing from the storyboard.
My question is how can I access things from both storyboard and things Ive added programmatically.
if you present the view controller then it will not give you default back button because when you present a controller it will not added in navigation stack of NavigationController so it won't give you that option.
If you want push controller do not use presentModalViewController.
Try like below
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
PhotosViewController *controller = [storyboard instantiateViewControllerWithIdentifier:#"PhotosViewController"];
[self.navigationController pushViewController:controller animated:YES];
and if you want to present controller then create manually add a back button like we have default in navigation back button and on it's click write below code to dismiss the controller.
[self dismissViewControllerAnimated:YES];
Hope this helps you.