我正在尝试实现一个使用获取结果控制器作为其数据源的AQGridView。
我不确定如何使用网格视图处理NSFetchedResultsController委托方法;即改变内容的内容。我理解如何将FRC用于其他网格视图数据源代理。
有人能指出我正确的方向吗?
答案 0 :(得分: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];
}
}
答案 1 :(得分:0)
由于AQGridView没有节,因此处理它的最佳方法是实现NSFethcedresultscontroller委托方法,并忽略与更新节相关的案例的任何代码。另外,请确保在没有sectionNameKeyPath的情况下初始化fetchrequest。
然后只需按照正常模式更新行,但使用NSIndexSet而不是NSIndexPath和InsertItemAtIndicies / DeleteItemAtIndicies而不是insertRowAtIndexPath / deleteRowAtIndexPath
我现在正在将AQGridView移动到CoreData,因此我会在完成后立即将更新发布到我的答案中...
答案 2 :(得分:-1)
当内容发生变化时,我会做
[self.gridView reloadData];
或类似的情况。它与tableview完全相同。