フェッチされた結果コントローラーをデータソースとして使用するAQGridViewを実装しようとしています。
グリッドビューを使用してNSFetchedResultsControllerデリゲートメソッドを処理する方法が特にわかりません。つまり、コンテンツを変更するものです。他のグリッドビューデータソースデリゲートにFRCを使用する方法を理解しています。
誰かが私を正しい方向に向けることができますか?
フェッチされた結果コントローラーをデータソースとして使用するAQGridViewを実装しようとしています。
グリッドビューを使用してNSFetchedResultsControllerデリゲートメソッドを処理する方法が特にわかりません。つまり、コンテンツを変更するものです。他のグリッドビューデータソースデリゲートにFRCを使用する方法を理解しています。
誰かが私を正しい方向に向けることができますか?
結果は次のようになります。
- (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];
}
}
AQGridViewにはセクションがないため、これを処理する最善の方法は、NSFethcedresultscontrollerデリゲートメソッドを実装し、更新されたセクションに関連するケースのコードを無視することです。また、sectionNameKeyPathを指定せずにfetchrequestを初期化してください。
次に、行を更新するための通常のパターンに従いますが、NSIndexPathの代わりにNSIndexSetを使用し、insertRowAtIndexPath/deleteRowAtIndexPathの代わりにInsertItemAtIndicies/DeleteItemAtIndiciesを使用します
現在、AQGridViewをCoreDataに移動しているので、完了したらすぐに回答の更新を投稿します...
コンテンツが変更されたとき、私は
[self.gridView reloadData];
またはあなたの場合はそのようなもの。テーブルビューとまったく同じです。