Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-27-2009, 01:30 PM   #1 (permalink)
Vishal
 
Join Date: Feb 2009
Location: Pune, India
Posts: 76
Default Navigation controller problem

Hi,

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
vishal is offline   Reply With Quote
Old 04-27-2009, 03:11 PM   #2 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
Default

Quote:
Originally Posted by vishal View Post
Hi,

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.)

Very simple rules for memory management in Cocoa

Code:
optionsViewController *optionsView = [[[optionsViewController alloc] initWithNibName:@"optionsView" bundle:nil] autorelease];
navControllerSettings = [[[UINavigationController alloc] initWithRootViewController:(UIViewController *) optionsView] autorelease];
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.
jsd is offline   Reply With Quote
Old 04-27-2009, 04:41 PM   #3 (permalink)
Vishal
 
Join Date: Feb 2009
Location: Pune, India
Posts: 76
Default

Quote:
Originally Posted by jsd View Post
You need to retain optionsViewController and navControllerSettings (although I'd probably use autorelease in this case.)

Very simple rules for memory management in Cocoa

Code:
optionsViewController *optionsView = [[[optionsViewController alloc] initWithNibName:@"optionsView" bundle:nil] autorelease];
navControllerSettings = [[[UINavigationController alloc] initWithRootViewController:(UIViewController *) optionsView] autorelease];
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.

Vishal N
vishal is offline   Reply With Quote
Old 04-27-2009, 04:58 PM   #4 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
Default

Quote:
Originally Posted by vishal View Post
Hi,

Thanks for the reply, but this won't helped me. It is still crashing. I tried with retain, autorelease and release.

Vishal N
does it crash with EXC_BAD_ACCESS or an exception? if exception, what is the message in the debugger?
jsd is offline   Reply With Quote
Old 04-28-2009, 07:06 PM   #5 (permalink)
Vishal
 
Join Date: Feb 2009
Location: Pune, India
Posts: 76
Default

Quote:
Originally Posted by jsd View Post
does it crash with EXC_BAD_ACCESS or an exception? if exception, what is the message in the debugger?
It is working on simulator but not working on iPhone.

Vishal N
vishal is offline   Reply With Quote
Old 04-28-2009, 07:22 PM   #6 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
Default

Quote:
Originally Posted by vishal View Post
It is working on simulator but not working on iPhone.

Vishal N
you didn't answer either of my questions.
jsd is offline   Reply With Quote
Old 05-01-2009, 08:41 PM   #7 (permalink)
Vishal
 
Join Date: Feb 2009
Location: Pune, India
Posts: 76
Default

Quote:
Originally Posted by jsd View Post
you didn't answer either of my questions.
Hi,

Sorry I could not debug it on device and it is working on simulator so could not answer your questions.

But I figured out where it is crashing.

Code:
[self presentModalViewController:self.navControllerSettings animated:YES];
Second time when I am trying to execute this line it is crashing.

What could be the problem here? Or do i need to take care while removing it .

I am just using syntax to remove it.
Code:
[self.navigationController dismissModalViewControllerAnimated:YES];
Vishal N
vishal is offline   Reply With Quote
Old 05-03-2009, 01:48 PM   #8 (permalink)
Vishal
 
Join Date: Feb 2009
Location: Pune, India
Posts: 76
Default

Quote:
Originally Posted by vishal View Post
Hi,

Sorry I could not debug it on device and it is working on simulator so could not answer your questions.

But I figured out where it is crashing.

Code:
[self presentModalViewController:self.navControllerSettings animated:YES];
Second time when I am trying to execute this line it is crashing.

What could be the problem here? Or do i need to take care while removing it .

I am just using syntax to remove it.
Code:
[self.navigationController dismissModalViewControllerAnimated:YES];
Vishal N
Hi,

I got this problem resolved.

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.

Code:
[self.navigationController dismissModalViewControllerAnimated:YES];
Is there any way to notify main view controller that navigation controller is finished?
vishal is offline   Reply With Quote
Old 05-03-2009, 03:07 PM   #9 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 536
Default

How did you resolve the first 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.
eddietr is offline   Reply With Quote
Old 05-04-2009, 11:40 AM   #10 (permalink)
Vishal
 
Join Date: Feb 2009
Location: Pune, India
Posts: 76
Default

Quote:
Originally Posted by eddietr View Post
How did you resolve the first 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.

Code:
[self presentModalViewController:self.navControllerSettings animated:YES];
thats why it was crashing for next time.

Vishal N
vishal is offline   Reply With Quote
Old 05-04-2009, 12:11 PM   #11 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
Default

Quote:
Originally Posted by vishal View Post
Hi,

I got this problem resolved.

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.

Code:
[self.navigationController dismissModalViewControllerAnimated:YES];
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.
jsd is offline   Reply With Quote
Reply

Bookmarks

Tags
navigation controller

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 330
22 members and 308 guests
@sandris, ADY, BrianSlick, dacapo, Dani77, Dattee, dre, HDshot, HemiMG, JasonR, MarkC, mer10, nibeck, prchn4christ, ryandb2, spiderguy84, themathminister, timle8n1, tomtom100, viniciusdamone, vogueestylee, vvenkatachallam
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,883
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, vvenkatachallam
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:11 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0