I'm trying to make my app remember which tab was last being viewed before the app quit, so that the app opens up to the same tab when it is next launched. This is the functionality of the iPhone's phone function: how can I do this?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- gactions CLI crashes on Windows when uploading goo
- how do you prevent page scroll in textarea on mobi
相关文章
- Windows - Android SDK manager not listing any plat
- Could I create “Call” button in HTML 5 IPhone appl
- Unable to process app at this time due to a genera
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
- Make Bootstrap tab Active on the bases of URL link
- Open iOS 11 Files app via URL Scheme or some other
- Can keyboard of type UIKeyboardTypeNamePhonePad be
I subclassed TabBarController and:
UPDATE
Objective C
Swift 3.2
In the UITabBar's Delegate, overwrite
and store item's index in NSUserDefaults. Next time your app starts, read it from there, and set it back to being selected. Something like this:
-first, you would set a delegate for your UITabBar, like this:
-in anObject, overwrite didSelectItem:
Note that you save a NSNumber, as int values cannot be serialized directly. When you start the app again, it will read and set the selectedIndex value from the defaults:
Here's how I did it. Both Methods are in the appDelegate and tabBarController is an instance variable.
Store the selected tab index in the NSUserDefaults preferences each time the user selects a new tab. Then when the app starts back up, load that value from the preferences and manually select that tab.
Here is the Swift 3 solution. Just set the class of your TabBarController to
RememberingTabBarController
in the Storyboard