我有一个 iOS 5 应用程序。
当我想将 View 推送到导航 Controller 时,应用程序崩溃:(
这是我的 appDelegate 部分:
- (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;
}
这是我推新的 View Controller 方法:
-(IBAction)startPressed:(id)sender
{
NSLog(@"startPressed: called");
//loading RootViewController (mainscreen view)
RootViewController *rootViewController=[[RootViewController alloc] init];
[self.navigationController pushViewController:rootViewController animated:YES];
}
应用程序在字符串
[self.navigationController pushViewController:rootViewController animated:YES];
处崩溃请帮帮我。如何解决这个问题呢?
最佳答案
UINavigationController 需要一个 rootviewController:
StartViewController *startViewController=[[StartViewController alloc] init];
self.navigationController=[[UINavigationController alloc] initWithRootViewControllr:startViewController];
[self.navigationController setNavigationBarHidden:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
更改
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
到
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
[pool release];
return retVal;
关于iphone - 当我将新 View Controller 推送到 self.navigation Controller 时应用程序崩溃了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8680728/