如何从委托外部设置超级视图?

发布于 2024-11-28 00:15:00 字数 240 浏览 0 评论 0原文

我的一个应用程序有一个奇怪的设计模式,其中有一个充当选项卡栏的工具栏。基本上,我将此工具栏添加到我的所有视图控制器中,并且工具栏本身包含指向我的应用程序中 3 个不同导航控制器的指针。当按下工具栏按钮之一时,它应该能够删除当前位于窗口上的导航控制器,并添加用户选择的导航控制器。我的问题是我不确定如何将新的导航控制器添加到超级视图中。我会实例化一个应用程序委托对象并将其添加到其中吗?或者我是否需要将指针作为类变量从我的应用程序委托发送到工具栏?任何帮助将不胜感激。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月依秋水 2024-12-05 00:15:00

在我看来,解决此问题的最佳方法是在应用程序委托中管理 UINavigationController 切换。您也可以在此处处理此过程中需要执行的所有清理工作。如果有有限数量的 UINavigationController 被切换,我可能只有几种方法来处理这个问题:

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,但是你明白了。不过,如果您需要在这些控制器之间共享状态,这将会改变。你?

编辑:为了访问应用程序委托,请调用[[UIApplication sharedApplication] delegate]

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文