用于跨选项卡保留 UI 状态的单例
我的应用程序使用选项卡栏来显示 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您使用的是
UITabBarController
还是UITabBar
本身?如果它本身就是一个UITabBar
,您可以简单地将 Twitter 栏放在顶部,而不用将其与主内容视图交换。如果您使用标签栏控制器,这可能会起作用:将您的应用程序委托(或其他一些单例)设置为委托,然后执行以下操作:
Are you using a
UITabBarController
or aUITabBar
by itself? If it's aUITabBar
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:
我假设您当前的视图控制器树如下所示:
您可以将其嵌套得更深:
然后将屏幕顶部的显示放入根
UIViewController
的导航栏中。或者完全将其更改为您自己的子类。I assume your current view controller tree looks like this:
You could nest this one deeper:
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.