10

フェッチされた結果コントローラーをデータソースとして使用するAQGridViewを実装しようとしています。

グリッドビューを使用してNSFetchedResultsControllerデリゲートメソッドを処理する方法が特にわかりません。つまり、コンテンツを変更するものです。他のグリッドビューデータソースデリゲートにFRCを使用する方法を理解しています。

誰かが私を正しい方向に向けることができますか?

4

3 に答える 3

7

結果は次のようになります。

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
{
  [gridView beginUpdates];
}

- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
       atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type
{
  switch(type)
  {
    case NSFetchedResultsChangeInsert:
      break; 
    case NSFetchedResultsChangeDelete:
      break;
  }
}

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

  ChannelPageViewController *currentPageController, *destinationPageController;

  NSIndexSet * indices = [[NSIndexSet alloc] initWithIndex: indexPath.row];
  NSIndexSet *newIndices = [[NSIndexSet alloc] initWithIndex:newIndexPath.row];

  switch(type) {
      case NSFetchedResultsChangeInsert:
        [gridView insertItemsAtIndices:newIndices withAnimation:AQGridViewItemAnimationNone];
      break;

      case NSFetchedResultsChangeDelete:
        [gridView deleteItemsAtIndices:indices withAnimation:AQGridViewItemAnimationNone];
        break;

      case NSFetchedResultsChangeUpdate:
        [gridView reloadItemsAtIndices:indices withAnimation:AQGridViewItemAnimationNone];
        break;

      case NSFetchedResultsChangeMove:
        [gridView deleteItemsAtIndices:indices withAnimation:AQGridViewItemAnimationNone];
        [gridView insertItemsAtIndices:newIndices withAnimation:AQGridViewItemAnimationNone];
        break;
   }
}

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
  [gridView endUpdates];
  if ([[frc fetchedObjects] count] == 1) {
    [gridView reloadData];
  }

}
于 2012-01-21T13:18:25.027 に答える
0

AQGridViewにはセクションがないため、これを処理する最善の方法は、NSFethcedresultscontrollerデリゲートメソッドを実装し、更新されたセクションに関連するケースのコードを無視することです。また、sectionNameKeyPathを指定せずにfetchrequestを初期化してください。

次に、行を更新するための通常のパターンに従いますが、NSIndexPathの代わりにNSIndexSetを使用し、insertRowAtIndexPath/deleteRowAtIndexPathの代わりにInsertItemAtIndicies/DeleteItemAtIndiciesを使用します

現在、AQGridViewをCoreDataに移動しているので、完了したらすぐに回答の更新を投稿します...

于 2011-12-29T18:42:16.580 に答える
-1

コンテンツが変更されたとき、私は

[self.gridView reloadData];

またはあなたの場合はそのようなもの。テーブルビューとまったく同じです。

于 2011-12-24T13:20:48.820 に答える