开发者

View controller calling a modal view

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 demon开发者_如何学Gostrates 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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜