How to: Save order of tabs when customizing tabs in UITabBarController

后端 未结 8 1216
终归单人心
终归单人心 2020-11-29 21:02

I am having problems finding any other information than the docs for how to save the tab order for my UITabBarController, so that the user\'s customization is saved for next

8条回答
  •  情歌与酒
    2020-11-29 21:31

    Simplified Rickard Elimää answer even further. "Swift" solution to saving and loading Customized ViewControllers using the delegate function of tabBarController CustomizingViewControllers.

    This is how I did it.

    class TabBarController: UITabBarController, UITabBarControllerDelegate {
    
        let kOrder = "customOrder"
    
        override func viewDidLoad() {
            super.viewDidLoad()
            self.delegate = self
    
            loadCustomizedViews()
        }
    
        func loadCustomizedViews(){
            let defaults = NSUserDefaults.standardUserDefaults()
    
            // returns 0 if not set, hence having the tabItem's tags starting at 1.
            let changed : Bool = defaults.boolForKey(kOrder)
    
            if changed {
                var customViewControllers = [UIViewController]()
                var tagNumber: Int = 0
                for (var i=0; i

提交回复
热议问题