首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >由NSFetchedResultsController支持的AQGridView

由NSFetchedResultsController支持的AQGridView
EN

Stack Overflow用户
提问于 2011-12-02 04:25:44
回答 3查看 751关注 0票数 10

我正在尝试实现一个使用fetched results控制器作为其数据源的AQGridView。

我不太确定如何使用网格视图处理NSFetchedResultsController委托方法;也就是内容不断变化的方法。我了解如何将FRC用于其他网格视图数据源委托。

谁能给我指个方向?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-01-21 21:18:25

结果应该看起来有点像这样:

代码语言:javascript
复制
- (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];
  }

}
票数 7
EN

Stack Overflow用户

发布于 2011-12-30 02:42:17

由于AQGridView没有节,因此处理它的最好方法是实现NSFethcedresultscontroller委托方法,并忽略与更新节相关的任何代码。还要确保在初始化fetchrequest时没有使用sectionNameKeyPath。

然后,只需遵循更新行的常规模式,但使用NSIndexSet而不是NSIndexPath和InsertItemAtIndicies/DeleteItemAtIndicies而不是insertRowAtIndexPath/deleteRowAtIndexPath

我现在正在将我的AQGridView移动到CoreData,所以我会在完成后立即发布我的答案的任何更新。

票数 0
EN

Stack Overflow用户

发布于 2011-12-24 21:20:49

当内容发生变化时,我会执行一个

代码语言:javascript
复制
[self.gridView reloadData];

在你的情况下也是这样。它与表视图完全相同。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8347801

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档