How to present view bottom to top when using navigationController - ios

ViewController *viewController = [[ViewController alloc] init];
[self.navigationController pushViewController:viewController animated:YES];
With above code, the "ViewController" moves from right-to-left.
Is it possible to present "ViewController" bottom-to-top?
I tried but it does not work.
viewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
I created "Navigation Controller" as follows
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
[navController setNavigationBarHidden:YES];

Most bottom-to-top animations of a new view controller involve the presentation of the view controller using:
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
Your code involves a navigation stack push, which is usually a right-to-left animation.

If you want to present a view controller then on button click event you have to write following code.
I hope this will work for you :
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:NSStringFromClass([DetailViewController class]) bundle:nil];
[self.navigationController presentViewController:detailViewController animated:YES completion:nil];

Related

How do I return back to RootView Controller from my last view controller?

I have 5 view controller and want to come back from the last view to 1st view controller
Call a function in which you have to change the app rootviewcontroller. set it as a navigationController
yourViewcontoller *viewController = [[yourViewContoller alloc] init];
UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:viewController];
self.window.rootViewController = navController;
If you're using storyboards, give the UINavigationController a Storyboard ID. You can then initiate it and present through the code:
UINavigationController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"<Storyboard ID>"];
[self presentViewController:vc animated:YES completion:nil];
Use this method on Animation splash screen
[self performSelector:#selector(setHidden:) withObject:nil afterDelay:2.0];
-(void) setHidden:(id)sender
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboare" bundle:nil];
YourVC* vController = (YourVC*)[Storyboard instantiateViewControllerWithIdentifier:#"storyboardId"];
UINavigationController *navcotoller=[[UINavigationController alloc]initWithRootViewController:vController];
self.window.rootViewController =navcotoller;
}
If you are using UINavigationController you could and should simply call
[self.navigationController popToRootViewControllerAnimated:YES];

Xcode UIViewController to customUIViewController without IB

I have a UIViewController, and inside that view controller I would like to call a CustomUIViewController without the use of Interface Builder. I've been using this and it works but it requires a storyboard ID.
UIStoryboard *storyboard = self.storyboard;
UIViewController *myVC = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:#"PageID"];
[self presentModalViewController:myVC animated:YES];
Is there a way of going from a UIViewController to a customViewController without the use of segues and IB?
Use this:
UIViewController *myVc = [[UIViewController alloc] init];
[self presentViewController:myVc animated:YES completion:nil];
This will obviously present a new blank view controller, if you want your PageID view then you replace UIViewController with the name of the PageID class (i,e the .h/.m file names)
So i'm assuming this:
PageID *myVc = [[PageID alloc] init];
[self presentViewController:myVc animated:YES completion:nil];
If you want it inside a navigation controller do:
PageID *myVc = [[PageID alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myVc];
[self presentViewController: navController animated:YES completion:nil];
OR if you don't want it to be modal (don't need to create a new navigation controller as it will be added to the existing navigation controller stack i.e. [self navigationController]:
[[self navigationController] pushViewController:myVc animated:YES];

iOS - how to set a navigation bar item in view controller?

I'm new to Objective-C and I want to add a UINavigationBar on my CatrgoryBIDViewController. I have proceed UIButton in InstructionBIDViewController.m file that should navigate to CatrgoryBIDViewController. Here is the function code:
- (IBAction)proceed:(id)sender {
viewControllercat =
[[CatrgoryBIDViewController alloc]
initWithNibName:#"CatrgoryBIDViewController"
bundle:nil];
UINavigationController *nav =
[[UINavigationController alloc]
initWithRootViewController:self.viewControllercat];
//[self.navigationController pushViewController:viewControllercat animated:YES];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
But it is not setting the UINavigationBar.
You should read the documentation here to understand the way a NavigationController is working. For your case:
If your current ViewController (where your proceed-method is implemented) has a NavigationController (is child of it), you can push another ViewController onto the stack of that NavigationController with
[self.navigationController pushViewController:viewControllercat animated:YES];
In this case you do not need to initialize another NavigationController, but in your CatrgoryBIDViewController in viewWillAppear you need to make the NavigationBar visible if it was not before already with
[self.navigationController setNavigationBarHidden:NO animated:YES];
If your current ViewController does not have a NavigationController, you can not push another ViewController on top of it and can not show the NavigationBar of it (although you can create your own NavigationBar and add it to the View of the ViewController, but without the usual Navigation-behaviour embedded).
If you open your ViewController programmatically (e. g. from the AppDelegate) you are correct to do so by your call:
viewControllercat = [[CatrgoryBIDViewController alloc] initWithNibName:#"CatrgoryBIDViewController" bundle:nil];
UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:self.viewControllercat];
My apologies - After having reread your question, I am going to tweak my answer some.
-(IBAction)proceed:(id)sender
{
viewControllercat = [[CatrgoryBIDViewController alloc] init];
UINavigationController * nc =
[[UINavigationController alloc] initWithRootViewController:vc];
// We now need to display your detail view but cannot push it.
// So display modally
[self presentViewController:nc animated:YES completion:Nil];
}
The above should result in your DetailViewController - CategoryBIDViewController being displayed on top of your InstructionBIDViewController and it should have a UINavigationController in it.

How to PushViewController From modalViewController

I have FavouriteViewController in which i have one button on click of button i am presenting a view modally called LoginViewController (using storyboard)
On this page(LoginViewController), i again have button, on click of that i want to push my view controller.
Is it possible ?
You can try below code.. It may help you to get your desired solution.
1) Present LoginViewController by write below code.
LoginViewController *login = [[[LoginViewController alloc]initWithNibName:#"LoginViewController" bundle:nil]autorelease];
UINavigationController *nc = [[[UINavigationController alloc] initWithRootViewController:login]autorelease];
nc.navigationBar.hidden = YES;
[self.navigationController presentModalViewController:nc animated:YES];
2) Now from LoginViewController, You can push your MyviewController as below.
MyviewController *adss = [[[MyviewController alloc]initWithNibName:#"MyviewController" bundle:nil]autorelease];
[self.navigationController pushViewController:adss animated:YES];
using UINavigationController
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:self.LoginViewController];
[self presentModalViewController:nav animated:YES];
after this you can push any view controller from presented view controller(LoginViewController)
Here it is
[self.parentViewController.navigationController pushViewController:newViewController animated:YES];

[self.navigationController pushViewController:ngView animated:YES]; not working

If i use
NGViewController *ngView = [[NGViewController alloc]initWithNibName:Nil bundle:Nil];
[self presentViewController:ngView animated:NO completion:nil];
above code the controller will go to NGViewController page.
But if I use this navigation controller
NGViewController *ngView = [[NGViewController alloc]initWithNibName:Nil bundle:Nil];
[self.navigationController pushViewController:ngView animated:YES];
the Controller will be in same page.
Can any one tell that what's the problem.
You should use this code
NGViewController *ngView = [[NGViewController alloc]initWithNibName:Nil bundle:Nil];
[self presentViewController:ngView animated:NO completion:nil];
after writting this line when then you you want go on different page with push view controller
UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:ngView];
[self.navigationController pushViewController:navigationController animated:YES];
I hope you will solve this issue by this code Good luck
Your self.navigationController is probably nil - check it out through debugging. Your self view controller is not within a UINavigationController.
Now i m using this code
NGViewController *ngView = [[NGViewController alloc]initWithNibName:Nil bundle:Nil];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 0.50];
[self presentViewController:ngView animated:NO completion:nil];
so that it wil give same effect other
Self Controller should have navigation controller (in Storyboard) in order to navigate.
[self.navigationController pushViewController:nextController animated:YES];
UINavigationController is a controller of controllers and it is designed to allow you to push and pop controllers and manage a hierarchy of your view's. And your navigationController property tells you whether your NGViewController is currently in a UINavigationController's hierarchy; if not (as in this case), the navigationController property returns nil.
You have to create your own navigation controller and then try to push the view controllers and thus build up a view hierarchy.
I normally would suggest this:
UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:firstviewController];
[self.window setRootViewController:navigationController];
navigationController.delegate = self;
navigationController.navigationBarHidden = YES;
you need to declare this in your first controller
NGViewController *ngView = [[NGViewController alloc]init];
[self.navigationController pushViewController:ngView animated:YES];

Resources