Rag*_*tto 19 iphone core-data ios watchkit wkinterfacetable
我有一个带有Tableview的iPhone应用程序,其数据来自CoreData.
相同的数据也会显示在观看应用中:
如果我从iPhone应用程序中添加一行:
我在Watch应用程序中重新加载数据:
我看到旧行空了!
如果停止手表应用程序并重新启动它,一切都会正确显示!
这是在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"] ]];
});
});
}
}
Run Code Online (Sandbox Code Playgroud)
这是我目前用来重新加载它的代码:
- (IBAction)reloadTable {
[self loadTable];
}
Run Code Online (Sandbox Code Playgroud)
我哪里错了?
Bon*_*nan 11
在@leolobato发布的链接中,实际上有一种解决方法.它确实解决了我的问题.
https://devforums.apple.com/message/1098875#1098875
当你改变行时,首先将它们设置为= @"".
例如,如果你的行有一个row.Label并且你要更改它,那么在row.Label.text = @"[Actual text]"之后再次执行row.Label.text = @""
归档时间: |
|
查看次数: |
9645 次 |
最近记录: |