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];
Related
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];
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];
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];
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];
I am new to iOS Application development, please help me how can I go from one view controller to another view controller on button click?
Follow the below step,let the button selector is
[button addTarget:select action:#selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
and implement the selector as
-(void)buttonClick{
UIViewController *controler = [[UIViewController alloc] init];
[self.navigationController pushViewController:controler animated:YES];}
and also make sure viewController has NavigationController embedded within it and replace UIViewController with the Controller you wish to push.
Use this code in your Objective-C function for navigation -
DashboardViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:#"DashboardView"];
[dvc setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:dvc animated:YES completion:nil];
Try this:
nextViewController *obj =[[nextViewController alloc]initWithNibName:#"nextViewController" bundle:nil];
[self.navigationController pushViewController:obj animated:YES];
[obj release];
You can use any of approach -
pushViewController: animated: - To Push the view on navigation stack
presentModalViewController:nc animated: - To present the view modally.
YourSecondViewcontroller *temp = [[YourSecondViewcontroller alloc]initWithNibName:#"YourSecondViewcontroller" bundle:nil];
[self.navigationController pushViewController:temp animated:YES];
//or
[self presentModalViewController:temp animated:YES];
Visit this reference for tutorial and working demo code
Hope, this will help you..enjoy
//SAViewController will be your destiation view
// import SAViewController.h file in your current view
SAViewController *admin = [[SAViewController alloc]initWithNibName:#"SAViewController" bundle:nil];
[self presentModalViewController:admin animated:YES];
[admin release];
Try this code:
- (IBAction)btnJoin:(id)sender {
SecondViewController *ViewController2 = [self.storyboardinstantiateViewControllerWithIdentifier:#"SecondViewController"];
[self.navigationController pushViewController: ViewController2 animated:YES];
}