Clear UITextField when user hits home button
I am new to iPhone dev and am trying to figure out the best way to开发者_JAVA技巧 clear a UITextField when the user hits the home button. I don't see any 'obvious' methods in the default tab bar .m file I am messing with. I am using xcode 4. Any ideas with sample code would be really helpful. Thanks.
You can use this method:
- (void)applicationWillResignActive:(UIApplication *)application
This one is used whenever the user leaves your app, that means from receiving a call to power button pressed and also pressing the home button as you asked.
In this method you "pause" nicely your app, and as soon as your applicationWillResignActive:
returns, your app has entered background.
Which home button? The device main button? Then you have to handle applicationDidEnterBackground in your AppDelegate to do it.
On ViewControllers, you can subscribe for UIApplicationDidEnterBackgroundNotification on NSNotificationCenter
精彩评论