我尝试从 AppDelegate.m 重新加载 TableView 数据,但没有成功。
这是代码(在 HomeViewController 中工作):
AppDelegate.m
...
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[self refreshTableData];
}
-(void)refreshTableData{
UINavigationController *navController = [[self.tabBarController viewControllers] objectAtIndex:0];
HomeViewController *home = [[navController viewControllers] objectAtIndex:0];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"MYTable" inManagedObjectContext:home.context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setFetchBatchSize:20];
[request setEntity:entity];
NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"orderEnt" ascending:YES];
NSArray *newArray = [NSArray arrayWithObject:sort];
[request setSortDescriptors:newArray];
NSError *error;
NSMutableArray *results = [[home.context executeFetchRequest:request error:&error] mutableCopy];
[home setArr:results];
//NSLog(@"%@", home.arr);//here is showed correct data
home.context = self.managedObjectContext;
[home.myTableView reloadData];
}
...
有人知道如何从 AppDelegate.m 重新加载数据吗?