我正在尝试实现一个使用fetched results控制器作为其数据源的AQGridView。
我不太确定如何使用网格视图处理NSFetchedResultsController委托方法;也就是内容不断变化的方法。我了解如何将FRC用于其他网格视图数据源委托。
谁能给我指个方向?
发布于 2012-01-21 21:18:25
结果应该看起来有点像这样:
- (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];
}
}发布于 2011-12-30 02:42:17
由于AQGridView没有节,因此处理它的最好方法是实现NSFethcedresultscontroller委托方法,并忽略与更新节相关的任何代码。还要确保在初始化fetchrequest时没有使用sectionNameKeyPath。
然后,只需遵循更新行的常规模式,但使用NSIndexSet而不是NSIndexPath和InsertItemAtIndicies/DeleteItemAtIndicies而不是insertRowAtIndexPath/deleteRowAtIndexPath
我现在正在将我的AQGridView移动到CoreData,所以我会在完成后立即发布我的答案的任何更新。
发布于 2011-12-24 21:20:49
当内容发生变化时,我会执行一个
[self.gridView reloadData];在你的情况下也是这样。它与表视图完全相同。
https://stackoverflow.com/questions/8347801
复制相似问题