I want my app to be loaded on the same view every time it is fully loaded out of memory, so when the app is closed and then opened again, it opens the same view (currently it’s one of the tabs in UITabBar).
I’d like to see code, not just description on how to do this, because I’m not very experienced in the iOS development.
Thanks in advance!
I want my app to be loaded on the same view every time it
Share
If your tab is a main menu, for example, that you always want to be loaded when the app is run, then consider not allowing multitasking by adding the following key in your app’sInfo.plistfile:This will ensure that your app quits when the home key is pressed and the
UIApplicationDelegatemethodapplicationwillterminate:is called.EDIT:
Okay, I think you need to keep track of your particular tab and/or the tab that the user is on, whenever this changes. Save this value in NSUserDefaults (plist) and check it each time the app starts up or becomes active – then you can switch to that tab if it’s not onthe correct one.
Is this what you are trying to do?
EDIT 2:
First step, wherever you listen out for button presses on your tab bar, you need to grab the integer value of the new selected index, like in the accepted answer here:
Switching to a TabBar tab view programmatically?
Then, you need to write this value (store/save it) to a .plist file. First, add a new property list file to your project, then open it in Xcode and add a new row, call it something simple like
SelectedTabwith a type of Number and say a value of 1337.In your app delegate, you need to tell your app that you have a new .plist that you need to be registered with the app, so in
application:didFinishLaunchingWithOptions:you need to do the following:Here’s how you can read and write to your
SelectedTabplist integer:To get the stored value…
To write a new value to your key…
You just need to pick the right place in your app delegate to perform this check, and then tell your tab bar to load the tab you want.
Hope this helps!