保存 UITabBar 布局
我听说当您使用 UITabBarCotroller 时,选项卡栏图标的自定义是免费的(看起来确实如此),但是我需要添加什么魔法才能使该布局粘在应用程序的实例上?
I had heard that the customizing of the tab bar icons was free when you use UITabBarCotroller (which it looks like it is) but what magic do I need to add to get that layout to stick across instances of the application?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UITabBarController
管理一个UIViewControllers
数组。您可以在应用程序退出时保留数组的顺序,并在应用程序启动时再次使用它。当您的应用退出时,您应该查看 tabBarControllers.viewControllers 数组,然后创建相应的名称或标识符数组并使用 NSUserDefaults 保存它。
当您的应用程序启动时,您可以查看该名称或标识符数组,并在创建视图控制器数组时使用它。然后将 tabBarControllers.viewControllers 设置为该数组。
抱歉,如果这很模糊,但您无法将视图控制器对象本身存储在应用程序的设置中,因此您需要提出其他类型的映射。如何最好地做到这一点取决于您的代码。
如果在 nib 文件中设置视图控制器数组,则意味着您需要从应用程序委托的
applicationDidFinishLaunching:
方法开始以编程方式执行此操作。applicationWillTerminate:
是保存订单的好地方,不过您也可以将对象设置为选项卡栏委托并保存所做的更改(这样,如果您的应用程序崩溃,它们就不会丢失) )。UITabBarController
manages an array ofUIViewControllers
. It is up to you to preserve the ordering of the array when the app quits and use it again when the app launches.When your app quits, you should look at the
tabBarControllers.viewControllers
array and then make a corresponding array of names or identifiers and save it usingNSUserDefaults
.When your app launches, you can look at that array of names or identifiers and use it when you create the array of view controllers. Then set
tabBarControllers.viewControllers
to that array.Sorry if that's vague, but you can't store the view controller objects themselves in app's settings, so you need to come up with some other kind of mapping. How best to do that depends on your code.
If the array of view controllers is being set in your nib file, that means you'll need to start doing it programmatically, from your app delegate's
applicationDidFinishLaunching:
method.applicationWillTerminate:
is a good place to save the order, though you could also set an object to be a tab bar delegate and save changes as they are made (so they won't be lost if your app crashes).