kiran
kiran

Reputation: 4409

how to add navigationcontroller to uiviewcontroller

employeeDetailed  = [[[EmployeeDetailedViewController alloc] initWithNibName:@"EmployeeDetailedViewController" bundle:nil] autorelease];
    UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:employeeDetailed] autorelease];
    [employeeDetailed release];
    [self.navigationController pushViewController:navController animated:YES];

I try this its saying bad access.[crash]

how to reslove this issue.

@ thanks in advance

Upvotes: 1

Views: 2810

Answers (4)

Atef
Atef

Reputation: 2902

The Best Way I found to present Navigation Controller in a specific part in your Application is like these:

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

Then in your myViewController.m use

[self.NavigationController pushViewController: XController animated:YES]; 

Upvotes: 0

user905582
user905582

Reputation: 524

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

This will work for you try this.

Upvotes: 2

beryllium
beryllium

Reputation: 29767

You cannot add UINavigationController to existed navigation stack. Instead of you need to show new navigation controller modal like this:

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

Upvotes: 0

Ian L
Ian L

Reputation: 5591

You have autorelease set in the first line (alloc/init)

You are then explicitly releasing the view controller on line three.

You are therefore over-releasing this object and causing the crash.

You can remove the [employeeDetailed release] line and it will be fine.

Upvotes: 1

Related Questions