I'm trying to use the pushViewController: animated: with a UIViewController. I have it housed in a UINavigationController with initWithRoot and it still doesn't work.
Here is my code? Am I doing something wrong?
CloudappSettingsViewController *cloud = [[CloudappSettingsViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:cloud];
[self pushViewController:nav animated:YES];
[cloud release];
It always crashes when it gets up to the [self pushViewController:nav animated:YES];
Any ideas?
Thanks
is "self" a UINavigationController?
It seems you are trying to push the navigation controller, but that is backwards. You should present the navigation controller and push additional views to it.
So the UIView you are in should already be in the nav controller then you would push cloud into that.
If this is in your app delegate, just add the UINavigationController as a subview to your app's window. If you want to present the UINavigationController as a modal view controller then do this:
[self presentModalViewController:nav animated:YES];
It will crash definitely because you set the nib to nil.
CloudappSettingsViewController *cloud = [[CloudappSettingsViewController alloc] initWithNibName:#"NibName goes here" bundle:nil];
Create a nib and assign it to your view controller.
Related
I have a UIViewController, I want to navigate from this view to my second view controller
SecondView *secondView=[[SecondView alloc] initWithNibName:#"SecondView" bundle:nil];
[self.navigationController pushViewController:secondView animated:YES];
[secondView release];
It doesn't work. It doesn't do anything and there is no error. What I'm missing?
SOLUTION
In Appdelegate file I've added a navigationcontroller.
UINavigationController *navCtrlr = [[UINavigationController alloc]initWithRootViewController:self.viewController];
[self.window setRootViewController:navCtrlr];
navCtrlr.delegate = self;
navCtrlr.navigationBarHidden = YES;
Is your view controller already inside a navigation controller otherwise it wont work. put an NSLog on self.navigationcontroller and see what it is printing
I have a table in my pop up view. But when clicking on a table row, it doesn't navigate to another view controller. Is there any direct method to navigate from popup view to another view controller ?
thanks in advance.
Code::
ProductListView1 *p = [[ProductListView1 alloc]initWithNibName:#"ProductListView1" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:p animated:YES];
Did you try [self presentViewController:p animated:YES completion:nil];
If you don't have a UINavigationController than you can't push a UIViewController.
Also note, that if you push a UIViewController in a UIPopoverController, it will just enlarge the UIPopover. If you want a whole new view to be displayed, than you must use presentViewController: and you could put a UIToolbar to a UINavigationController onto that modal view.
ContentViewController of popover, should be a navigation controller.
First create navigationController with rootViewController as tableViewController(first controller to be displayed in popover)
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:tableViewController];
and then present navigationController in popover
[popOver setContentViewController:navigationController animated:YES];
And then you can push another controller in tableViewController's didSelectRowAtIndexPath: delegate method
ProductListView1 *p = [[ProductListView1 alloc]initWithNibName:#"ProductListView1" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:p animated:YES];
I'm extremly new to iphone and I have the following misunderstanding.
All over internet the tutorials about how to use NavigationController programatically it says:
NavigationController must be declared in applicationDidFinishLaunching and must be init with a root.After that you can add views to it.
I have this:
A UIViewController class meaning(AdiViewController.h, AdiViewController.m and AdiViewController.xib) and no Delegate file meaning no applicationDidFinishLaunching method.
What I wanna do is from my class-AdiViewController when pressing a button to go to another view.
I understand that I need a NavigationController which should retain my views having the root AdiViewController.
But my problem is where should I initializate that NavigationController in viewDidAppear??...cause I don't have the Delegate files.
If you could provide a minimal example with this small issue of mine it would be great.I'm sure that for those how are senior this is nothing but still I don't get it.Thanks
NavigationController must be declared in applicationDidFinishLaunching -> this is not true.
In your AdiViewController if you have button when you push that button you want to load navigation Controller right ?
// Hook this IBAction to your button in AdiViewController
- (IBAction)pushNavController
{
AnotherViewController* rootView = [[AnotherViewController alloc] initWithNibName:#"Anotherview" bundle:nil];
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:rootView];
[rootView release];
[self presentModalViewController:navController animated:YES];
[navController release];
}
If you are in AnotherViewController i.e., you are in root view controller of Navigation controller. You need to push and pop view controllers from there. For example if you have a button in AnotherViewController:
// push next view controller onto navigation controller's stack
- (IBAction)pushNextViewController
{
NextViewController* nextView = [[NextViewController alloc] initWithNibName:#"NextView" bundle:nil];
[self.navigationController pushViewController:nextView animated:YES];
[nextView release];
}
// Similarly if you want to go back to AnotherViewController from NextViewController you just pop that from navigation controller's stack
- (IBAction)pushNextViewController
{
[self.navigationController popViewControllerAnimated:YES];
}
I am fairly new to iPhone. I have a peculiar problem. I am adding a view controller as a subView to the current view. And then I want to push a new view controller from it. The problem is when I try to do pushViewController, it is not responding.
For example, in CurrentViewController I have added NewViewController's view as subView
[self.view addSubView : NewViewController.view]
Now From NewViewController, on the click of a button I am doing the following :
SecondViewController *secondVC = [SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
[self.navigationController pushViewController:secondVC animated:YES];
Here the secondVC doesn't get pushed to the stack.
If you have used view based application, You have to use this code.
SecondViewController *secondVC = [SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
// [self.navigationController pushViewController:secondVC animated:YES];
[self presentModalViewController:secondVC animated:YES];
If you want to use navigation controller in your appln. First you have to add navigation controller in your appln and then only will navigate the view.
Perhaps the problem is that method is called pushViewController not pushToViewController. Try
SecondViewController *secondVC = [SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
[self.navigationController pushViewController:secondVC animated:YES];
// don't forget release here
[secondVC release];
In navigationcontroller application , i used
ViewController *modalViewController=[[ViewController alloc]initWithNibName:#"ViewController" bundle:nil];
[[self navigationController]presentModalViewController:modalViewController animated:NO];
[modalViewController release];
above code will load an anotherviewcontroller....
I want to push one moreviewcontroller from this viewcontroller(ViewController)...
Can any one help me?
Thanks in advance...
If you actually want to push view controllers in the modal view then the modal view needs to be a UINavigationController. So you would do something like this:
ViewController *modalViewController=[[ViewController alloc]initWithNibName:#"ViewController" bundle:nil];
UINavigationController *modalNavController = [[UINavigationController alloc] initWithRootViewController:modalViewController];
[modalViewController release];
[self.navigationController presentModalViewController:modalNavController animated:NO];
[modalNavController release];
I generally wouldn't recommend doing it because it is confusing to the user, but in some cases it makes sense.
Do you mean "push" as in pushViewController, or as in presentModalViewController?
In presentModalViewController