Reputation: 1393
I have an iOS 5 application. When I want to push view to my navigation controller, the application crashes :(
Here's my appDelegate part:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.navigationController=[[UINavigationController alloc] init];
StartViewController *startViewController=[[StartViewController alloc] init];
[self.navigationController pushViewController:startViewController animated:YES];
[self.navigationController setNavigationBarHidden:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController=self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
Here's my pushing new view controller method:
-(IBAction)startPressed:(id)sender
{
NSLog(@"startPressed: called");
//loading RootViewController (mainscreen view)
RootViewController *rootViewController=[[RootViewController alloc] init];
[self.navigationController pushViewController:rootViewController animated:YES];
}
Application crashed at a string [self.navigationController pushViewController:rootViewController animated:YES];
Help me, please. How to solve this problem?
Upvotes: 1
Views: 4871
Reputation: 585
I also have some issue with pushViewController. I checked all target memberships and obtain that my xib file wasn't added to necessary target. This helps me. I think you also should check your xib file.
Upvotes: 0
Reputation: 1393
Solved the problem. I changed `[self.navigationController pushViewController:vc animated:NO] and debug gave me the warning that the view outlet was not set. So I connected view from interface builder and the problem is gone. Thanks everybody for help
Upvotes: 3
Reputation: 492
i have same problem with pushViewController but when i try something like this
UINavigationController *rootViewController = (UINavigationController *)[[[UIApplication sharedApplication] keyWindow] rootViewController];
NSLog(@"NavControler:%@, %@", self.navigationController, rootViewController);
i get the same pointres, and the NSArray have 1 item. The problem is somewhere else.
If someone can help and add some code that will work to pushViewController because i have the correct NavigationController but when i try to push the ViewControler i get error
ViewController* NextView = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
UINavigationController *rootViewController = (UINavigationController *)[[[UIApplication sharedApplication] keyWindow] rootViewController];
[rootViewController pushViewController:NextView animated:YES];
Please could someone explained this issues for me.
Upvotes: 1
Reputation: 5499
It's a strange way to deal with UINavigationController. In your case I would like to know if it works if you change
self.navigationController=[[UINavigationController alloc] init];
StartViewController *startViewController=[[StartViewController alloc] init];
[self.navigationController pushViewController:startViewController animated:YES];
to
StartViewController *startViewController=[[StartViewController alloc] init];
self.navigationController=[[UINavigationController alloc] initWithRootViewController:startViewController];
If your app still crashes, it would be interesting to know if you override -loadView
method of StartViewController
class as you don't initialize it with – initWithNibName:bundle:
Upvotes: 1
Reputation: 69459
A UINavigationController wants a rootviewController:
StartViewController *startViewController=[[StartViewController alloc] init];
self.navigationController=[[UINavigationController alloc] initWithRootViewControllr:startViewController];
[self.navigationController setNavigationBarHidden:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
Change the
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
to
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
[pool release];
return retVal;
Upvotes: 4