Reputation:
I have 2 views we are dealing with. Main View, and Sub View.
Main View's tablecell's string shows the count of the number of objects in that cell's subView. When I delete a cell from the subview, and go back to the mainView, the string that shows the count should go down by 1. Right now this string is not changing until I restart the app.
Any ideas how I can fix this? The count is being pulled from a NSFetch.
Edit: Added Code
- (void)configureCell:(TDBadgedCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
NSDate *today = [NSDate date];
NSDate *thisWeek = [today dateByAddingTimeInterval: -604800.0];
NSDate *thisMonth = [today dateByAddingTimeInterval: -2629743.83];
else if (indexPath.row == 2)
{
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
self.predicate = [NSPredicate predicateWithFormat:@"(timeStamp >= %@) AND (timeStamp <= %@)", thisWeek, today];
[fetchRequest setPredicate: predicate];
[fetchRequest setEntity:[NSEntityDescription entityForName:@"Session" inManagedObjectContext:managedObjectContext]];
NSError *error = nil;
NSArray *results = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
NSLog(@"Fetch error: %@", error);
cell.badgeString = [NSString stringWithFormat:@"%i", [results count]];
[fetchRequest release];
}
else if (indexPath.row == 3)
{
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
self.predicate = [NSPredicate predicateWithFormat:@"(timeStamp >= %@) AND (timeStamp <= %@)", thisMonth, today];
[fetchRequest setPredicate:predicate];
[fetchRequest setEntity:[NSEntityDescription entityForName:@"Session" inManagedObjectContext:managedObjectContext]];
NSError *error = nil;
NSArray *results = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
NSLog(@"Fetch error: %@", error);
cell.badgeString = [NSString stringWithFormat:@"%i", [results count]];
[fetchRequest release];
}
else if (indexPath.row == 4)
{
cell.badgeString = [NSString stringWithFormat:@"%i", [[self.fetchedResultsController fetchedObjects] count]];
}
Upvotes: 0
Views: 190
Reputation: 3
You need to be sure that you're getting the proper handle on the tableview, if you've made an accessor for your tableview in the header file then you need to call it by that name in the viewWillLoad method.
Upvotes: 0
Reputation: 5122
If your data is in fact being updated correctly on the model side of things, you should be able to call
[tableView reloadData];
and everything will update correctly. You can probably put this in viewWillAppear.
Hope this helps.
Upvotes: 2