【发布时间】:2014-04-10 10:01:27
【问题描述】:
我使用 Core Data 和 MagicalRecord 来管理items,可以启用或禁用。有
数据存储中 Item 实体上的 enabled 标志。 item 也有一个title。最后我
使用NSFetchedResultsController 在表格视图中显示items。表视图有两个
部分:第一个用于启用的项目,第二个用于禁用的项目。所有项目
默认情况下启用。 禁用项的单元格具有不同的背景颜色(黄色)。
更复杂一点的是,单元格是从一个 nib 文件中加载的,如下所示:
- (void)viewDidLoad
{
// ...
self.items = [Item fetchAllGroupedBy:@"enabled"
withPredicate:nil
sortedBy:@"enabled,createdOn"
ascending:NO
delegate:self];
// ...
[self.tableView registerNib:[UINib nibWithNibName:@"CustomTableViewCell" bundle:nil]
forCellReuseIdentifier:@"CustomCellReuseIdentifier"];
// ...
}
// ...
- (CustomTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *reuseIdentifier = @"CustomCellReuseIdentifier";
CustomTableViewCell *cell =
(CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:reuseIdentifier
forIndexPath:indexPath];
[self configureCell:cell forRowAtIndexPath:indexPath];
return cell;
}
- (void)configureCell:(CustomTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
Item *item = [self.items objectAtIndexPath:indexPath];
cell.titleLabel.text = item.title;
if (!item.enabled.boolValue) {
cell.backgroundColor = [UIColor colorWithRed:0.999 green:0.895 blue:0.452 alpha:1.000];
}
}
// ...
现在,当我禁用一个item,删除它,然后创建一个新的item 同名, 新 item 的单元格 具有黄色背景,即使新 item 已启用。如果我检查 item 本身,它确实启用,所以它只是保持黄色的单元格。
请问有谁知道问题出在哪里?
【问题讨论】:
标签: ios core-data nsfetchedresultscontroller magicalrecord