2012-01-10 55 views
1
employeeDetailed = [[[EmployeeDetailedViewController alloc] initWithNibName:@"EmployeeDetailedViewController" bundle:nil] autorelease]; 
    UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:employeeDetailed] autorelease]; 
    [employeeDetailed release]; 
    [self.navigationController pushViewController:navController animated:YES]; 

我試試這個它說壞的訪問。[碰撞]如何添加navigationcontroller到的UIViewController

如何reslove這個問題。

@謝謝提前

回答

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]; 

這會爲你工作試試這個。

+0

其爲我工作的感謝! – kiran 2012-01-10 14:06:37

1

你已經在第一線自動釋放設定(分配/初始化)

你是那麼明確地釋放在三線視圖控制器。

因此,您過度釋放此對象並導致崩潰。

您可以刪除[employeeDetailed發佈]行,它會沒事的。

+0

@thanks IanL忘記內存問題。!你能幫我看看如何推ViewViewController它不推動我 – kiran 2012-01-10 13:26:40

+0

正如鈹提到的,你不能推動一個新的UINavigationController到現有的導航堆棧。你指的是self.navigationController,所以我假設當前的控制器是堆棧的一部分。在這種情況下,您應該可以簡單地使用:[self.navigationController pushViewController:employeeDetailed animated:YES]; – 2012-01-10 13:37:47

+0

yeap我使用[self.navigationController pushViewController:employeeDetailed animated:YES];控制器仍然沒有做任何事情! – kiran 2012-01-10 13:44:07

0

您不能將UINavigationController添加到現有導航堆棧。相反的,你需要表現出新的導航控制器模式是這樣的:

employeeDetailed = [[[EmployeeDetailedViewController alloc] initWithNibName:@"EmployeeDetailedViewController" bundle:nil] autorelease]; 
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:employeeDetailed] autorelease]; 
[self presentModalViewController: navController]; 
+0

我不想要presentmodalviewcontroller先生。我需要pushViewController – kiran 2012-01-10 13:27:23

+0

,然後只推'employeeDetailed',沒有'navController'。 – beryllium 2012-01-10 13:39:13

+0

yeap我做了它不工作! – kiran 2012-01-10 13:46:28

0

我發現呈現導航控制器在應用程序的特定部分的最佳方式是這樣的:

MyViewController *myViewController = [[MyViewController alloc]initwithnibname :@"MyViewController"]; 
    UINavigationController *myNavC = [[UINavigationController alloc]initWithRootViewController:myViewController]; 
在myViewController.m

然後 使用

[self.NavigationController pushViewController: XController animated:YES]; 
相關問題