【发布时间】:2013-09-08 16:31:47
【问题描述】:
我有一个基于标签的应用程序,并且希望每次在标签之间切换时重新加载数据。所以我使用了viewWillAppear:,它被调用但数据不会重新加载。这可能是使用大量[NSUserDefault] 的结果吗?
这是我的代码:
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self reloadData];
}
-(void)reloadData {
//Loading all the data
totalApples = [[NSUserDefaults standardUserDefaults]integerForKey:@"totalApples"];
[self setText:[NSString stringWithFormat:@"%.01f", totalApples] withExistingAttributesInLabel:self.applesLabel];
applesPerSecond = [[NSUserDefaults standardUserDefaults]integerForKey:@"applesPerSecond"];
[self setText:[NSString stringWithFormat:@"%.01f", applesPerSecond] withExistingAttributesInLabel:self.applesPerSecondLabel];
applesPerClick = [[NSUserDefaults standardUserDefaults]integerForKey:@"applesPerClick"];
}
【问题讨论】:
-
ViewWillAppear,傻我
-
哦,那有什么明显的问题吗? ;-)
-
您能解释一下您所说的“但这仅在一半的时间里有效”是什么意思吗?
-
有没有在 viewWillAppear 中设置断点并验证只调用了一半的时间?
-
在将数据写入
NSUserDefautls时,您是否调用synchronize?
标签: ios objective-c nsuserdefaults