开发者

How to Set Superview From Outside of Delegate?

I have a weird design pattern for one of my aps where I have a tool bar that acts as a tab bar. Basically I add this toolbar to all of my view controllers, and the tool bar itself contains pointers to the 3 different nav controllers in my app. When one of the toolbar buttons is pushed, it should be able开发者_高级运维 to remove the nav controller that currently is on the window, and add the one the user has selected. My problem is I'm not sure how to add the new navcontroller to the superview. Would I instantiate an app delegate object and add it to that? Or would I need to send a pointer from my app delegate to the tool bar as a class variable? Any help would be appreciated.


It seems to me that the best way to go about this would be to manage your UINavigationController switching in your app delegate. You can look after all the cleanup that you need to do during this process here, as well. If there are a finite number of UINavigationControllers that get switched out, I might just have a few methods to take care of this:

App delegate .h file:

@property (nonatomic, retain) UINavigationController *currentNavController;

App delegate .m file:

    @synthesize currentNavController = _currentNavController;

    - (void)loadNavControllerOne
    {
        self.currentNavController = ...; // Set up your new controller
        self.window.rootViewController = self.currentNavController;
    }

    - (void)loadNavControllerTwo
    {
        // Similar to -(void)loadNavControllerOne
    }

Abridged, but you get the idea. This will change if you need to share state between these controllers, though. Do you?

EDIT: In order to access the app delegate, call [[UIApplication sharedApplication] delegate].

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜