用于跨选项卡保留 UI 状态的单例

发布于 2024-11-27 23:09:12 字数 945 浏览 0 评论 0原文

我的应用程序使用选项卡栏来显示 5 个差异视图。每个视图的顶部都有一个窄条,显示 Twitter 提要。Twitter 提要应在所有选项卡中保持其外观。

-----------------------------------------
| twitter feed scrolling to the left    | < this block stays here, text scrolls
-----------------------------------------
|                                       |
|                                       |
|                                       |
|           main bit of the view        |
|          changes according to tab     |
|                                       |
|                                       |
|                                       |
-----------------------------------------
|       |       |       |       |       |
|       |       |       |       |       | < tab bar
|       |       |       |       |       |
-----------------------------------------

我无法弄清楚这里的代码的最佳模式是什么。我是否应该在单例中保留 twitter feed 详细信息(包括 UI?)并使用 viewDidAppear 将它们粘贴到视图中?或者有更好的方法来实现这一点吗?

My app uses a tab bar to display 5 diff views. Each of these views has a narrow strip at the top which displays a twitter feed.. The twitter feed should maintain it's appearance across all tabs.

-----------------------------------------
| twitter feed scrolling to the left    | < this block stays here, text scrolls
-----------------------------------------
|                                       |
|                                       |
|                                       |
|           main bit of the view        |
|          changes according to tab     |
|                                       |
|                                       |
|                                       |
-----------------------------------------
|       |       |       |       |       |
|       |       |       |       |       | < tab bar
|       |       |       |       |       |
-----------------------------------------

I can't work out what would be the best pattern here for the code. Should I retain the twitter feed details (including UI?) in a Singleton and stick them into view with viewDidAppear? Or is there a better way of implementing this?

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

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

发布评论

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

评论(2

油饼 2024-12-04 23:09:12

您使用的是 UITabBarController 还是 UITabBar 本身?如果它本身就是一个 UITabBar ,您可以简单地将 Twitter 栏放在顶部,而不用将其与主内容视图交换。

如果您使用标签栏控制器,这可能会起作用:将您的应用程序委托(或其他一些单例)设置为委托,然后执行以下操作:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    // Have an ivar called twitterBar.
    [viewController.view addSubview:twitterBar];
}

Are you using a UITabBarController or a UITabBar by itself? If it's a UITabBar by itself, you could simply put the twitter bar across the top and don't swap it out with the main content view.

If you're using a tab bar controller, this might work: set your app delegate (or some other singleton) as the delegate, and do:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    // Have an ivar called twitterBar.
    [viewController.view addSubview:twitterBar];
}
爱要勇敢去追 2024-12-04 23:09:12

我假设您当前的视图控制器树如下所示:

UITabBarController
    ViewOneController
    ViewTwoController
    etc.

您可以将其嵌套得更深:

UINavigationController
    UITabBarController
        ViewOneController
        ViewTwoController
        etc.

然后将屏幕顶部的显示放入根 UIViewController 的导航栏中。或者完全将其更改为您自己的子类。

I assume your current view controller tree looks like this:

UITabBarController
    ViewOneController
    ViewTwoController
    etc.

You could nest this one deeper:

UINavigationController
    UITabBarController
        ViewOneController
        ViewTwoController
        etc.

Then put the display at the top of the screen into the root UIViewController's navigation bar. Or change it for your own subclass completely.

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