0

コアデータを使用してアプリを開発しています。ユーザーはカテゴリを追加でき、ユーザーはセルをカテゴリに追加できます。セルが の場合done、ユーザーはセルを完了に設定しました。カテゴリが呼び出された場合、ビューはすべてのセルが であるかどうかをチェックしますdone。すべてのセルが Core Data で完了すると、カテゴリが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。カテゴリに移動して戻ると、カテゴリは に設定されdoneます。私は多くのことを試しました (呼び出し viewWillAppear (すべてのセルが完了し、またはに設定されているかどうかを確認するNSString)を AppDelegate ( 、および) に含めます)。donenot donedidFinishLaunchingWithOptionsapplicationWillEnterForegroundapplicationDidBecomeActive

誰かが私を助けてくれることを願っています。

4

1 に答える 1

0

セルを設定してカテゴリを確認することで問題を解決しました(ifステートメントを使用)。

于 2012-12-27T16:10:00.207 に答える