Xcode TableViewStyle没有';不随核心数据变化(有时)

Xcode TableViewStyle没有';不随核心数据变化(有时),xcode,core-data,uitableview,Xcode,Core Data,Uitableview,我正在开发一个具有核心数据的应用程序。 用户可以添加类别,然后用户可以将单元格添加到类别中。 如果单元格已完成,则用户将单元格设置为完成。 如果类别被调用,视图将检查是否所有单元格都已完成。 如果所有单元格都在核心数据中完成,则会将类别设置为done(使用NSString:@“catisdone”)。 这一切都很好。 我使用以下代码更改CellStyle: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIn

我正在开发一个具有核心数据的应用程序。 用户可以添加类别,然后用户可以将单元格添加到类别中。 如果单元格已完成,则用户将单元格设置为完成。 如果类别被调用,视图将检查是否所有单元格都已完成。 如果所有单元格都在核心数据中完成,则会将类别设置为
done
(使用
NSString:@“catisdone”
)。 这一切都很好。 我使用以下代码更改CellStyle:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath called");

static NSString *notDoneCellIdentifier = @"NotDoneCatCell";
static NSString *doneCellIdentifier = @"DoneCatCell";

LWCats *currentCat = [self.cat objectAtIndex:indexPath.row];

NSString *cellIdentifier;
if ([currentCat.donecat isEqualToString:@"catisdone"]) {
    cellIdentifier = doneCellIdentifier;
} else {
    cellIdentifier = notDoneCellIdentifier;
}

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}

// Configure the cell...

cell.textLabel.text = currentCat.namecat;
cell.detailTextLabel.text = currentCat.rewardcat;

return cell; }
这在大多数情况下效果很好。 如果在tableView中有一个类别,则称之为(当然)。 如果我添加了一个类别,它会工作好,然后我会转到该类别并添加一个单元格,将此单元格设置为
完成
,保存它并关闭应用程序。 如果我再次打开应用程序,则类别未更改为
done
,当我转到类别并返回时,类别设置为
done
。 我在AppDelegate中尝试了很多事情(包括调用视图将显示(检查是否所有单元格都已完成,并将
NSString
设置为
done
not done
)(
didfishlaunchingwithoptions
applicationWillEnterForeground
applicationIDbecomeactive


我希望有人能帮助我。

我通过设置单元格(使用if语句)来检查类别,从而解决了这个问题