コアデータを使用してアプリを開発しています。ユーザーはカテゴリを追加でき、ユーザーはセルをカテゴリに追加できます。セルが の場合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 ( 、および) に含めます)。done
not done
didFinishLaunchingWithOptions
applicationWillEnterForeground
applicationDidBecomeActive
誰かが私を助けてくれることを願っています。