2009-07-22 7 views
1

私は現在、訪問した各場所をその種類別に保存するホリデージャーナルを開発中です。たとえば、レストラン名は「食品」セクションに保存する必要があります。私はコアデータを扱い、問題なくテーブルを作成することができました。しかし、問題は、私は場所(順序を変更するため、テーブルビューの必要性)の種類を変更しようとするたびに、私はエラーメッセージを得るでしょうです:UITableViewの結果を取得するためのコントローラを並べ替える

2009-07-22 21:04:58.150 HolidayTest[8662:20b] Serious application error. Exception was caught during Core Data change processing: *** -[NSCFArray removeObjectAtIndex:]: index (4) beyond bounds (4) with userInfo (null) 
2009-07-22 21:04:58.151 HolidayTest[8662:20b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray removeObjectAtIndex:]: index (4) beyond bounds (4)' 

私はフェッチ結果コントローラのデリゲートは、テーブルを更新している知っています。しかし、問題はフェッチコントローラが独自のセクションと行のデータを更新していないことです。簡単な方法は、ユーザーが型を変更した場合に、フェッチ結果コントローラにデータを再フェッチするように指示することです。ただし、データを効率的に管理する方法ではありません。


答えていただきありがとうございます。TahoeWolverine。ここでコードは、私は、ユーザーがテーブルビュー上の行を選択してその型を変更する場所の型を変更します。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSIndexPath *selectionIndexPath = [NSIndexPath indexPathForRow:selected inSection:0]; 
    UITableViewCell *checkedCell = [tableView cellForRowAtIndexPath:selectionIndexPath]; 
    checkedCell.accessoryType = UITableViewCellAccessoryNone; 

    [[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark]; 
    selected = indexPath.row; 
    NSManagedObject *aType = [siteType objectAtIndex:indexPath.row]; 
    self.site.type = [aType valueForKey:@"name"]; 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    [self.delegate TypeSelectionController:self didChangeType:YES]; 
} 

このコードは、私はエラーメッセージが表示されます、次のコード

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller 
{ 
    [self.tableView beginUpdates]; 
} 


- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath { 

    UITableView *tableView = self.tableView; 

    switch(type) 
    { 
     case NSFetchedResultsChangeInsert: 
      [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade]; 
      break; 

     case NSFetchedResultsChangeDelete: 
      [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
      break; 

     case NSFetchedResultsChangeUpdate: 
      [self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath]; 
      break; 

     case NSFetchedResultsChangeMove: 
      [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
      [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:newIndexPath.section] withRowAnimation:UITableViewRowAnimationFade]; 
      break; 
    } 

} 

- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id) <NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type 
{ 


    switch(type) 
{ 

     case NSFetchedResultsChangeInsert: 
      [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade]; 
      break; 

     case NSFetchedResultsChangeDelete: 
      [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade]; 
      break; 
    } 

} 


- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller 
{ 
    [self.tableView endUpdates]; 
} 

を実行フェッチ結果コントローラのデリゲートに対応.......

+0

あなたが作るコードの呼び出しを投稿してください – TahoeWolverine

答えて

0

ことが困難ですあなたがここで何を意味しているかを正確に伝えるために、あなたの配列の終わりを越えて取り除こうとしているようです。それが原因で起こっていることを知るのは難しいです。

私はこれを実装した場合、私は

A)テーブルからエントリを削除します:

[tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade]; 

B)のデータ構造からエントリを削除します。

C)データ(タイトル、任意の他)を変更します。

D)はデータ構造にする必要があるエントリを追加します。

E)は、それが表にあるべきエントリを追加します。助け

[tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade]; 

希望。あなたが質問を更新すれば、私は目を離さない。

関連する問題