【发布时间】:2015-01-29 15:22:36
【问题描述】:
我想调用 ApplicationDidEnterBackground。 我在 MainViewController.m 中使用此代码
- (void)applicationDidEnterBackground:(UIApplication *)application {
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:_savedText];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:@"savedText"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
但我认为它从未被调用过。我试图将内容放在应用程序委托中,但由于找不到“_savedText”而出现错误。我需要将“_savedText”导入到应用程序委托还是应该这样做?
【问题讨论】:
-
有这个定义吗:
MainViewController: UIViewController < UIApplicationDelegate >? -
在里面放一个断点,看看有没有被调用。
-
现在我尝试在其中放置一个断点。它在 appDelegate 中调用,但在 MainViewController 中没有调用。定义如下所示: MainViewController : UITableViewController
标签: objective-c xcode save appdelegate shutdown