「チェックリスト」項目を表示するための TableView を持つ UIViewController があります。この ViewController には、ユーザーが新しいチェックリスト項目を追加するための別の UIViewController をモーダルに表示するセグエをトリガーするボタンもあります。
すべてのチェックリスト項目は CoreData に保存されます。
新しい CoreData エンティティが作成され、SecondViewController
. ユーザーはchecklist
、 の却下をトリガーするボタンを押す前に、好きなだけ項目を追加できますSecondViewController
。ここでSecondViewController
は形式的に提示されているので、その活動は とはまったく関係がないと仮定しFirstUIViewController
ます。
FirstViewController
を含むUITableView
には、再度NSFetchedResultsController
CoreData でフェッチ要求を実行し、すべてのデータを にフィードする がありますUITableView
。NSFetchedResultsController のデリゲートも this を指していFirstUIViewController
ます。
問題は、 の却下後、が新しいチェックリスト エンティティの挿入に気づき、UITableView 内に新しいエンティティを挿入しSecondViewController
たように見えることです。ただし、奇妙なことに、この新しく挿入された行には適切な. ラベルに何も記載されていないブランクのみが表示されます。UITableView
UITableCell
cell.textlabel
UITableViewCell
以下は、私が設定する方法UITableViewCell
です。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ChecklistCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
ChecklistItem *item = [self.fetch_controller objectAtIndexPath:indexPath];
cell.textLabel.text = item.name;
}
これが私がNSFetchedResultsControllerDelegateのために持っているものです
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath
{
switch (type) {
case NSFetchedResultsChangeInsert:
NSLog(@"*** controllerDidChangeObject - NSFetchedResultsChangeInsert");
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
を強制する[self.tableView reloadData]
と役立つようです。これは、このメソッドを呼び出すボタンを 1 つ追加したため、セルのラベルが更新され、それに応じて更新されたためです。
したがって、 の解任後に呼び出されることを期待して、これを試しましたSecondViewController
。ただし、ログに記録されたためにメソッドが呼び出されReload Data!
ますが、どういうわけか、tableView には新しく追加されたセルのラベルが正しく表示されません。
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self performFetch];
[self.tableView reloadData];
NSLog(@"Reload Data!");
}
ここで何が間違っているのだろうか。self.tableView
の却下後、どういうわけかがリロードされませんSecondViewController
。助言がありますか?
OK、さらに奇妙なのは、私が[self.tableView reloadData]
内部で試したこと- (void)viewDidAppear:(BOOL)animated
です。新しい tableViewCell はまだラベルを正しく表示しません。ただし、30 秒待つと、魔法のようにラベルが表示されます。これは、私の iPhone/iPhone シミュレーターが考えるのに時間がかかるということですか?