I am junior iOS dev and trying to use MMDrawerController.
I have MainStoryboard with 4 views.
NavigationController (embed on CenterViewController controller)
CenterViewController
LeftViewController
AboutViewController
I've added button on Navigation left item on CenterViewController and tap on it open/close my sidemenu.
But if I wan't to change center view with this code
ViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:#"AboutViewController"];
if (vc)
[appDelegate.drawerController setCenterViewController:vc withCloseAnimation:YES completion:nil];
It works fine but I have no navigation left button. Why?
Thanks
My solution is:
AboutViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:#"AboutViewController"];
if (vc)
{
if ( [appDelegate.drawerController.centerViewController isKindOfClass:[UINavigationController class]] )
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UINavigationController *navController = (UINavigationController *)appDelegate.drawerController.centerViewController;
[appDelegate.drawerController toggleDrawerSide:MMDrawerSideLeft animated:YES completion:nil];
[navController pushViewController:vc animated:YES];
}
}
Related
The first ViewController is managed by a NavigationController, and it has a UIWebView. The WebView modules has click events to push a ViewController in the NavigationController.
But now, the ViewController which is init by code is normal, and which is init by storyboard is abnormal, the navigation bar was disappeared. It only occurs in iOS8 and earlier Version.
PS: The Init Code is like this:
Code:
ViewController *vc = [[ViewController alloc]init];
[self.navigationController pushViewController:vc animated:YES];
Storyboard:
ViewController *vc = [ViewController defaultViewControllerWithStoryboard:#"StoryboardName"];
[self.navigationController pushViewController:vc animated:YES];
Thank You.
MainViewController* presentController = [self.storyboard instantiateViewControllerWithIdentifier:#"StoryBoardidentifier"];
[self.navigationController pushViewController:presentController animated:YES];
if its not working try this Normally yourStoryBoardName is Main:
UIStoryboard* storyBoard = [UIStoryboard storyboardWithName:#"YourStoryBoardName" bundle:nil];
MainViewController* presentController = [storyBoard instantiateViewControllerWithIdentifier:#"StoryBoardIdentifier"];
[self.navigationController pushViewController:presentController animated:YES];
I'd like to know if it's possible to push a ViewController of the NavigationController in full screen without tabbar and navigation bar. My problem is as follow:
My app has a NavigationController embedded in a TabBarController. In the NavController I show a FirstVC with a button to navigate to another VC. Right now I do a modal presentation to show the SecondVC. But in this SecondVC I have a tableview where a button returns a ThirdVC. This ThirdVC needs to have the navigationbar and tabbar of the FirstVC. Maybe I need to show the SecondVC with a push on the NavigationController of the first but it seems that I can't reproduce my full screen animation ...
To make it simple:
FirstVC ===> SecondVC (modal presentation) ====> ThirdVC (modal presentation):
This is my app at this time without navbar or tabbar on the ThirdVC.
Thanks in advance.
Edit
The modal presentation to the SecondVC is like that:
- (IBAction)detailButtonClicked:(id)sender {
SecondVC *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"SecondVC"];
vc.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:vc animated:YES completion:nil];
}
From the SecondVC to the ThirdVC I use again presentViewController because I can't use pushViewController in modal. The result is predictable: I don't have a navigation bar or a tabbar.
I tried different things like the one below or addChildView as subview to my FirstVC:
- (IBAction)detailButtonClicked:(id)sender {
SecondVC *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"SecondVC"];
UINavigationController *childNavigationController = [[UINavigationController alloc] initWithRootViewController:vc];
childNavigationController.navigationBarHidden = YES;
[self.navigationController presentViewController:childNavigationController animated:YES completion:nil];
}
and in the SecondVC
- (IBAction)changeButtonClicked:(id)sender {
ThirdVC *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"ThirdVC"];
[self.navigationController pushViewController:vc animated:YES];
}
I can't access my tabbar or navigation bar in the ThirdVC either...
What I do in your is I added following code improvement.
- (IBAction)buttonClicked:(id)sender {
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main"
bundle: nil];
SecondViewController *vc = (SecondViewController*)[mainStoryboard
instantiateViewControllerWithIdentifier: #"SecondVC"];
vc.delegate = self;
[[APP_DELEGATE window] addSubview:vc.view];
[self addChildViewController:vc];
}
Main line of code is addchildViewController.
Here You can download the sample code of yours.
I am developing an iOS app and using storyboards. In my storyboard, I had set a SWRevealViewcontroller and it works fine.
Now i have a new requirement, and i need to present a viewcontroller, which is an option from the rear_vc in the reveal from my appdelegate, after receive a push notification.
In appdelegate i'm using the next method to instantiate and show the view controller
- (void)showViewController {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
TheViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"vc"];
[self.window makeKeyAndVisible];
[self.window.rootViewController presentViewController:vc animated:YES completion:NULL];
}
So, since the viewcontroller is an option from the rear viewcontroller, i need to add gesture recognizer to display menu using
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
[self.view addGestureRecognizer:self.revealViewController.tapGestureRecognizer];
This is where i have the problem, because self.revealViewController is nil, and the app crashes in this lines, because segue is not coming directly from the rear viewcontroller.
In rear viewcontroller prepare for segue method we need to add this lines
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ( [segue isKindOfClass: [SWRevealViewControllerSegue class]] ) {
SWRevealViewControllerSegue *swSegue = (SWRevealViewControllerSegue*) segue;
swSegue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc) {
UINavigationController* navController = (UINavigationController*)self.revealViewController.frontViewController;
[navController setViewControllers: #[dvc] animated: NO ];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
};
}
}
But from appdelegate i can't do that, how can achieve this ?
Thanks
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 have three View controller A,B,C.I have navigation controller attached to A view controller.In A i have some buttons,I have attached the button segue to B view controller.Onclick of the button i go to the B view controller.On B View controller i have UITableView on click of table view item i am launching the C view controller.below is the code for that
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row==0)
{
NSLog(#"first cell");
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:#"BusinessCard"];
[self presentViewController:vc animated:YES completion:nil];
}
else if(indexPath.row==1)
{
NSLog(#"second cell");
}
else if(indexPath.row==2)
{
NSLog(#"third cell");
}
}
But on C view controller the navigation Bar is not appearing.I think C view controller is not linked to the Navigation Controller.
You use navigationController push method to display navigation bar in C viewController
try this code:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:#"BusinessCard"];
[self.navigationController pushViewController:vc animated:YES];
Use the code below
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:#"BusinessCard"];
UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:vc];
[self presentViewController:nav animated:YES completion:nil];
You need to present it using UINavigationController as modal.
Hope it helps.
use this:
[self.navigationController pushViewController:vc animated:YES];
You can use "Push" segue and embed your ViewController in Navigation Controller, and then use its Navigation Controller's functions like pushViewController and popViewControllerAnimated
Answer are all correct, but i just want to explain things..
//This line gets the storyboard with the name "Main" which contains all
//the setup you made for UI (User interface)
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
//While this like gets the view inside your storyboard with
//storyboard ID/indentifier `BusinessCard `
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:#"BusinessCard"];
//Lastly, this line is correct presenting the viewcontroller BUT this doesn't add your
//viewcontroller to the array of viewControllers inside navigationController
//
//Also, this line makes you present the viewController above the
//rootViewController of window which is in your case the navigationController
//
This is you Error
[self presentViewController:vc animated:YES completion:nil];
//This is what you are looking for, and the correct one for your implementation
//
//This will let you add the `vc`(viewController) to the array of viewController
//in navigationController, to confirm that you can check the `self.navigationController.viewControllers`
//which will return the array of viewController inside your navigationController
This is the Answer
[self.navigationController pushViewController:vc animated:YES];
Hope this helps you, and my explanation is apprehendable.. Cheers