我有一个基于选项卡的应用程序,并且每次在选项卡之间切换时都想重新加载数据。所以我使用viewWillAppear:
了 which 被调用但数据不会重新加载。这可能是使用大量[NSUserDefault]
's 的结果吗?这是我的代码:
-(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"];
}