I am using one navigation controller in my application. I am having one main view(with main view controller) and few options views. Options views are viewed by navigation controller when a button clicked on main view's toolbar.
Everything works as expected for first time. When I came back to main view from navigation controller and tries again to go to option view(i.e. navigation controller) my application crashes.
Following is my code,
Code:
//Jump to navigation controller from main view controller
optionsViewController *optionsView = [[optionsViewController alloc] initWithNibName:@"optionsView" bundle:nil];
navControllerSettings = [[UINavigationController alloc] initWithRootViewController:(UIViewController *) optionsView];
[self presentModalViewController:self.navControllerSettings animated:YES];
//Code to go back to main view from navigation controller
[self.navigationController dismissModalViewControllerAnimated:YES];
What is correct mechanism to handle navigation controller? Do I need to release/dealloc the navigation controller or options view?
I am using one navigation controller in my application. I am having one main view(with main view controller) and few options views. Options views are viewed by navigation controller when a button clicked on main view's toolbar.
Everything works as expected for first time. When I came back to main view from navigation controller and tries again to go to option view(i.e. navigation controller) my application crashes.
Following is my code,
Code:
//Jump to navigation controller from main view controller
optionsViewController *optionsView = [[optionsViewController alloc] initWithNibName:@"optionsView" bundle:nil];
navControllerSettings = [[UINavigationController alloc] initWithRootViewController:(UIViewController *) optionsView];
[self presentModalViewController:self.navControllerSettings animated:YES];
//Code to go back to main view from navigation controller
[self.navigationController dismissModalViewControllerAnimated:YES];
What is correct mechanism to handle navigation controller? Do I need to release/dealloc the navigation controller or options view?
Sample code will help better.
Vishal N
You need to retain optionsViewController and navControllerSettings (although I'd probably use autorelease in this case.)
I'm far from a Cocoa memory management expert but I do know one key rule: If you alloc/init something, you MUST follow up with retain/release or autorelease. Put that on a sticky on the side of your monitor.
I'm far from a Cocoa memory management expert but I do know one key rule: If you alloc/init something, you MUST follow up with retain/release or autorelease. Put that on a sticky on the side of your monitor.
Hi,
Thanks for the reply, but this won't helped me. It is still crashing. I tried with retain, autorelease and release.
My new problem is I want to notify my main view controller that navigation controller is done with its task. so when below statement gets call my main view controller should know that navigation controller finished.
Remember this is not a free help desk. The point is to learn and share. So if you could post an explanation of how you solved your first issue, it could help someone else with a similar problem.
Remember this is not a free help desk. The point is to learn and share. So if you could post an explanation of how you solved your first issue, it could help someone else with a similar problem.
Hey,
I was releasing the navigation controller immediately after displaying it, i.e. after following statement.
My new problem is I want to notify my main view controller that navigation controller is done with its task. so when below statement gets call my main view controller should know that navigation controller finished.
Is there any way to notify main view controller that navigation controller is finished?
there's nothing automatic. you'll have to arrange to pass in the calling controller to the modal view, and then when the modal view is finished, it can call some method on the caller.