employeeDetailed = [[[EmployeeDetailedViewController alloc] initWithNibName:@"EmployeeDetailedViewController" bundle:nil] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:employeeDetailed] autorelease];
[employeeDetailed release];
[self.navigationController pushViewController:navController animated:YES];
我试着这说不好访问。[崩溃]
如何解决此问题。
@提前感谢
答案 0 :(得分:2)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Set the view controller as the window's root view controller and display.
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:self.viewController] autorelease];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}
employeeDetailed = [[[EmployeeDetailedViewController alloc] initWithNibName:@"EmployeeDetailedViewController" bundle:nil] autorelease];
[self. navigationController presentModalViewController: navController];
这对你来说很有用。
答案 1 :(得分:1)
您在第一行(alloc / init)中设置了autorelease
然后,您将在第三行显式释放视图控制器。
因此,您过度释放此对象并导致崩溃。
您可以删除 [employeeDetailed release] 一行,就可以了。
答案 2 :(得分:0)
您无法将UINavigationController添加到现有导航堆栈。而不需要像这样显示新的导航控制器模式:
employeeDetailed = [[[EmployeeDetailedViewController alloc] initWithNibName:@"EmployeeDetailedViewController" bundle:nil] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:employeeDetailed] autorelease];
[self presentModalViewController: navController];
答案 3 :(得分:0)
我发现在应用程序的特定部分中呈现导航控制器的最佳方式如下:
MyViewController *myViewController = [[MyViewController alloc]initwithnibname :@"MyViewController"];
UINavigationController *myNavC = [[UINavigationController alloc]initWithRootViewController:myViewController];
然后在你的myViewController.m中 使用
[self.NavigationController pushViewController: XController animated:YES];