How can i present/dismiss viewcontroller from bottom to top in navigationcontroller? - ios

I want to show animation from bottom to top when i am pushing viewController to navigationController?Do any have idea to do it?
RegisterViewController *registerView = (RegisterViewController *)[self.storyboard instantiateViewControllerWithIdentifier:#"RegisterViewController"];
Present
[self presentViewController:registerView animated:YES completion:nil];
Dismiss
[self dismissViewControllerAnimated:YES completion:nil];
Is there any way to achieve this in navigationController?

Don't link Storyboard
Present ViewController with this code
It Will Present from bottom to top
UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"MYUnicornViewController"]; // Change the view controller name
[self.navigationController presentViewController:vc animated:YES completion:nil];
Dismiss ViewController with this code
It Will dismiss from top to bottom
[self.navigationController dismissViewControllerAnimated:YES completion:nil];

You can present the view controller like as answered by #PinkeshGjr,
I am adding code to add navigation bar without the custom view suggested by #Pinkeshgjr.
Instead you can simply add your view controller in Navigation controller and present.
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];//Change your storyboard name
UIViewController* myCopntroller = [storyBoard instantiateViewControllerWithIdentifier:#"myViewController"];//Your view controller
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:myCopntroller];//Added in navigation controller
[self presentViewController:nav animated:YES completion:nil];//Present you viewcontroller

Objective C:
Present from Bottom to Top
RegisterViewController *registerView = (RegisterViewController *)[self.storyboard instantiateViewControllerWithIdentifier:#"RegisterViewController"];
[self.navigationController presentViewController:registerView animated:YES completion:nil];
Dismiss from Top to Bottom
[self dismissViewControllerAnimated:YES completion:nil];
Swift:
Present from Bottom to Top
let registerView = self.storyboard?.instantiateViewController(withIdentifier: "RegisterViewController") as! RegisterViewController
self.navigationController?.present(registerView, animated: true, completion: nil)
Dismiss from Top to Bottom
self.navigationController?.dismiss(animated: true, completion: nil)

Related

MMDrawerController where I need to add sidemen buttons?

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];
}
}

Present a ViewController that is embedded in Navigation Controller

I have a situation wherein a storyboard made VC(embedded in NavController) should be presented programmatically.
SomeVC -> presents NavController(rootVC) -> rootVC -> pushes subVC
on this representation, subVC should have a back button to go back to rootVC, but I can't implement it this way. Will be providing sample codes that I have already tried.
this pushes the rootVC directly:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"storyBoard" bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:#"rootVC"];
[self.navigationController presentViewController:vc animated:YES completion:nil];
also tried pushing the navigationController itself, ID has been set on storyboard:
UINavigationController *navController = [storyboard instantiateViewControllerWithIdentifier:#"navigationController"];
[self presentViewController:navController animated:YES completion:nil];
EDIT: storyboard implementation looks like this
I'm not sure if I understand you correctly. You want to present a navigation controller and have those rootVC and subVC already in it, right? So after presenting, you want the subVC to be presented with the back button right away.
If that's the case you need to tell the navigation controller to push the subVC before presenting it
UINavigationController *navController = [storyboard instantiateViewControllerWithIdentifier:#"navigationController"];
UIViewController *subVC = [storyboard instantiateViewControllerWithIdentifier:#"subVC"];
[navController pushViewController:subVC animated:NO];
[self.navigationController presentViewController:vc animated:YES completion:nil];

PushViewController in fullscreen

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.

Need to return to the presenting UIViewController from within a presented UINavigationController

In MyMainViewController, I present a navigation controller like this:
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"Main_iPhone" bundle:nil];
UINavigationController* nc = [storyboard instantiateViewControllerWithIdentifier:#"NAVIGATION_CONTROLLER_ID"];
[self presentViewController:nc animated:YES completion:nil];
Later, from somewhere within the view hierarchy of the UINavigationController, I need to return to MyMainViewController. How can I do this?
(Note: MyMainViewController is defined in a .XIB, and not in the storyboard where the UINavigationController and it's children are defined.)
It sounds like you have modally presented a NavController that you want to remove. Modally presented VC's can remove themselves.
Somewhere in your NavController add:
[self dismissViewControllerAnimated:YES completion:^{
NSLog(#"Dismissed nav controller modally");
}]
[self.navigationController popToViewController:[[self.navigationController viewControllers] objectAtIndex:2] animated:YES];
I gues you know the index of your view controller. If you simply want to return to the rootViewController you can do it like
[self.navigationController popToRootViewControllerAnimated:YES];
If you want to push new viewController to the navigation stack just do it like
MyMainViewController *mainController = [[MyMainViewController alloc] initWithNibName:#"MyMainViewController" bundle:nil];
[self.navigationController pushViewController:desController animated:YES];
Returning to the previous viewController would be
[self dismissViewControllerAnimated:YES completion:nil];

IOS retain a viewcontroller

How can i go from a uitabbarcontroller to a viewcontroller in fullscreen, retaining all the data and views/tabs on the uitabbarcontroller?
tks
Did you want to hide the TabBar or show a new view, but once you're done with the new view have the TabBar be unaffected?
In the case of the latter try something like:
ViewController *vc = [[ViewController alloc] initWith...];
[self presentModalViewController:vc];
Add ViewController on TabBar in fullScreen then:
ViewController *vc = [[ViewController alloc] initWithNibName:#"ViewController " bundle:nil];
[self presentViewController:vc animated:YES completion:NULL];
Now dissmiss that Modal Controller like this in any event( of button may be)
[self removeFromParentViewController];
After this your tabbar will as it is:

Resources