I have an app for iPhone with a Tableview, whose data comes from CoreData.
The same data are also displayed in a watch app:
If I add a row from the iPhone app:
and I reload data in the Watch app:
I see the old rows empty!
If the stop the watch app and I start it again, everything appears correctly!
This is the code to fill the Tableview in the watch app
-(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"] ]];
});
});
}
}
This is the code I am currently using to reload it:
- (IBAction)reloadTable {
[self loadTable];
}
Where am I wrong?
In the link @leolobato posted, there is actually a workaround. It did solve my problem.
https://devforums.apple.com/message/1098875#1098875
when you change your rows just set them to =@"" first.
For example, if your row has a row.Label and you are changing it, do row.Label.text = @"" then again right after row.Label.text =@"[Actual text]"