Reputation: 23
I have VC1 with label (show number of tasks I have). In VC2 I have all my tasks in tableView and I can delete them (the tasks saved in COREDATA)
The problem is if I have 5 tasks the label show me "05" but when i go to VC2 and delete one task, and come back to VC1 it will show me "05" and "04" at same label and same position, its like VC1 do 'screen shot'. it will be normal when i go to other VC or when I reload APP.
why this happend? and how can I fix it?
tnx, and sorry about my English.
In viewDidAppear:
// fetchData FROM CORE DATA Tasks //
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entityTasks = [NSEntityDescription entityForName:@"Device" inManagedObjectContext:[self managedObjectContext]];
[fetchRequest setEntity:entityTasks];
NSError *errorTasks = nil;
fetchedObjectsTasks = [[self managedObjectContext] executeFetchRequest:fetchRequest error:&errorTasks];
if (fetchedObjectsTasks == nil) {
NSLog(@"Problem with fetch! %@",errorTasks);
}
numberOfIssues = [NSMutableArray arrayWithObjects:[NSString stringWithFormat:@"%lu",(unsigned long)fetchedObjectsTasks.count],nil];
In TableCell:
numberOfIssueLabelView.frame = CGRectMake(224, 11, 20, 21);
numberOfIssueLabelView = [[UILabel alloc] initWithFrame:numberOfIssueLabelView.frame];
numberOfIssueLabelView.text = [numberOfIssues objectAtIndex:(indexPath.row)];
numberOfIssueLabelView.font = [UIFont systemFontOfSize:15.0f];
numberOfIssueLabelView.textColor = [UIColor whiteColor];
[cell addSubview:self.numberOfIssueLabelView];
return cell;
When you not add or delete task its work good, I think VC1 need get some refresh.
Upvotes: 0
Views: 70
Reputation: 8988
Use a fetchedResultsController to managed the tableView. That way any updates get correctly reflected in the UITableView. See my comment above re sample apps that demonstrate this in action.
Upvotes: 0
Reputation: 1413
Either use the NSNotificationCenter to send a notification to VC1 to update the number, or create a protocol VC2Delegate
and have VC1 set itself as the delegate of VC2, so VC2 can contact it's delegate when necessary to update the count.
Also ensure that you're not instantiating multiple labels but rather just instantiating one and updating it when necessary.
Upvotes: 1