views:

66

answers:

2

How can I reliably determine the name of the view controller that called a modal view from within that modal view? The app has a singleton so I was planning to add a view controller there and save the name of the calling view controller. .parentController gives me the name of the nav controller.

EDIT I tried a sample project and it did just as mine did so I think maybe were not on the same page.  I appreciate your working with me on this one.  I downloaded a project from

http://sites.google.com/site/iphonesdktutorials/sourcecode/UINavigationControllerWithToolbar.zip?attredirects=0

added 2 lines and changed 1 and it demonstrates what I am getting.   It took me all of 5 minutes, if that. In RootViewController.m, info_clicked (line 147), above the last line add,

NSLog(@"calling: %@", [[self navigationController] visibleViewController]); 

then, per your instructions, in the last line change self.navigationController to self.  This controller is what I want to get from the modal.  Then in InfoViewController.m, viewDidLoad (line 35), before the closing curly brace add,

NSLog(@"Parent: %@", [self parentViewController]); 

Change the Base SDK Project Settings to 4.0, Build, open your console and press the Info Button on the bottom.  I'm getting UINavigationController for parentViewController and I want RootViewController.

+1  A: 

You're probably using [self.navigationController presentModal...] instead of [self presentModal...]. If you use self, parentViewController will work.

jtbandes
Nav based app.  Using [self parentViewController] in modal. Always gives UINavigationController.  Using [[self navigationController] visibleViewController] in the calling class gives me the correct name of it's own view controller.  I want that info from within the modal.
Hal Stevens
Sorry. Didn't specifically address your reply: No, I am indeed using [self presentModalViewController:addNavCon animated:YES]; All use a nav controller.
Hal Stevens
@Hal Stevens: then... it should work fine! Have you tried making a new project to test with?
jtbandes
@jtbandes: Please see my EDIT above. Thanks.
Hal Stevens
A: 

See edit above.

Hal Stevens