Hi Amy -
amyhughes wrote:
When the app is first built and run in the simulator both DidLoad and WillAppear are running. When I press the home button WillDisappear does
not get called, and when I re-launch the app by touching its icon neither DidLoad nor WillAppear are called. It works for the class instructor, though the SDK and ios have been updated since the class was recorded.
Yes, the difference in behavior is due to the update. You're seeing the difference between iOS 3 and iOS 4. iOS 4 has the ability to keep your app in memory when the home button is pressed so that when you later touch its icon (or return from another activity), the app can return to the foreground in exactly the same state it was in before.
Methods like viewDidLoad, viewDidAppear, viewDidUnload, etc. aren't automatically called when the app switches from active to inactive and vice-versa. Similarly, the state of the app will be preserved during an inactive-active cycle regardless of whether it was saved and retrieved using NSUserDefaults. If you want to take some actions when the app becomes either inactive or active, you can use app delegate methods such as [applicationDidBecomeActive:|http://developer.apple.com/iphone/library/document ation/UIKit/Reference/UIApplicationDelegate
Protocol/Reference/Reference.html#//appleref/doc/uid/TP40006786-CH3-SW10].
For more info, see [Clearing value from textfield etc on exit|http://discussions.apple.com/thread.jspa?messageID=11935724�]. The link provided by Tony Wright in that thread might be especially helpful: [Screw Multitasking: How To Make Your iOS 4 Apps Exit For Real|http://maniacdev.com/2010/07/screw-multi-tasking-how-to-make-your-ios-4-ap ps-exit-for-real>. The article shows how to set a key in your info.plist file which will cause the app to actually terminate when you press the home button. You should then observe the same behavior you would get on iOS 3, as described in your course notes.
Also remember that your app +really will+ terminate when the system shuts down. After a fresh system startup the app won't be restored to any prior session state without using NSUserDefaults or some other scheme involving persistent memory.
Unrelated question: how do you format code here? (dashes and square brackets not appearing, but are there)
See the [yellow alert|http://discussions.apple.com/ann.jspa?annID=749] which is the first topic in this forum. To see how your post will appear, click the preview tab just above the Reply editor panel.
\- Ray