【发布时间】:2011-05-10 16:41:54
【问题描述】:
在我的项目中,我在我的应用委托中使用NSMutableArray 和NSUserDefaults:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
array = [[NSMutableArray alloc] initWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"array"]];
和
- (void)applicationWillTerminate:(UIApplication *)application {
[[NSUserDefaults standardUserDefaults] setObject:array forKey:@"array"];
问题是当我写在一个类中,例如firstViewController.m,在viewdidload:
NSLog(@"number of element:%d", appDelegate.array.count);
结果总是“2”,但如果我写了
[appDelegate.array removeAllObjects];
那么计数的结果是“0”。当我重新启动应用程序时,计数再次为“2”。重新启动应用程序时,如何使数组中的对象为零?
【问题讨论】:
-
这是你完整的 applicationWillTerminate 方法吗?特别是,您是否跟进了同步调用?
-
是的,这是我完整的 applicationWillTerminate 方法?我不明白第二个问题...
标签: objective-c ios nsmutablearray nsuserdefaults