我正在处理2个观点。主视图和子视图。
Main View的tablecell字符串显示该单元格子视图中对象数量的计数。当我从子视图中删除一个单元格并返回到mainView时,显示计数的字符串应该减少1.此时此字符串不会更改,直到我重新启动应用程序。
我有什么想法可以解决这个问题?计数是从NSFetch中提取的。
编辑:添加代码
- (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]];
}
答案 0 :(得分:2)
如果您的数据实际上在模型方面正确更新,您应该可以调用
[tableView reloadData];
一切都会正确更新。你可以将它放在viewWillAppear中。
希望这有帮助。
答案 1 :(得分:0)
您需要确保在tableview上获得正确的句柄,如果您已在头文件中为tableview创建了一个访问器,那么您需要在viewWillLoad方法中使用该名称调用它。