我有一个带有 Tableview 的 iPhone 应用程序,其数据来自 CoreData。
手表应用中也会显示相同的数据:
如果我从 iPhone 应用程序添加一行:
我在 Watch 应用程序中重新加载数据:
我看到旧行是空的!
如果停止手表应用程序并重新启动它,一切都会正确显示!
这是在手表应用程序中填充 Tableview 的代码
-(void)awakeWithContext:(id)context{
[super awakeWithContext:context];
[self loadTable];
}
-(void)loadTable{
NSLog(@"loadTableData");
NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Data"];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Data"
inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
NSSortDescriptor *sortByDate = [[NSSortDescriptor alloc] initWithKey:@"sortedDateAndTime" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortByDate, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
self.watchMArray = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];
// [self.watchTableView setRowTypes:self.watchMArray];
[self.watchTableView setNumberOfRows:self.watchMArray.count withRowType:@"data"];
for (NSInteger i = 0; i < self.watchMArray.count; i++)
{
WatchTableCell *cell = [self.watchTableView rowControllerAtIndex:i];
NSManagedObject *data = [self.watchMArray objectAtIndex:i];
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
//Background Thread
UIImage *foto =[self loadImageFromData:[data valueForKey:@"imageData"]];
dispatch_async(dispatch_get_main_queue(), ^(void){
//Run UI Updates
[cell.watchImage setImage:foto];
[cell.watchDate setText:[NSString stringWithFormat:@"%@", [data valueForKey:@"dataEOra"] ]];
});
});
}
}
这是我目前用来重新加载它的代码:
- (IBAction)reloadTable {
[self loadTable];
}
我哪里错了?