Tag: uicollectionreusableview

如何正确插入或删除UICollectionView补充视图

简短的问题: 有没有一种方法来添加和删除类似于insertItemsAtIndexPaths: deleteItemsAtIndexPaths:或甚至reloadItemsAtIndexPaths:方法的performBatchUpdates:块中的单元格和部分的补充视图? 长解释: 我使用UICollectionView与部分。 单元格像网格一样布置,每行最多可以有6个单元格。 如果单元的总数不填满某个部分的所有行,我将添加其他补充视图。 额外的补充意见只是填补了空白。 所以结果应该是每个部分完全填充所有可用的单元格,并且(可能的)剩余空白点填充补充视图。 所以每行有6个视觉元素,一个单元格或一个补充视图。 为了实现这一点,我实现了一个自定义的UICollectionViewFlowLayout基于布局与以下prepareLayout:实现: – (void)prepareLayout { [super prepareLayout]; self.supplementaryViewAttributeList = [NSMutableArray array]; if(self.collectionView != nil) { // calculate layout values CGFloat contentWidth = self.collectionViewContentSize.width – self.sectionInset.left – self.sectionInset.right; CGFloat cellSizeWithSpacing = self.itemSize.width + self.minimumInteritemSpacing; NSInteger numberOfItemsPerLine = floor(contentWidth / cellSizeWithSpacing); CGFloat realInterItemSpacing = (contentWidth – (numberOfItemsPerLine * […]

自动调整UICollectionView标题

我正在尝试做一个待办事项列表类应用程序的详细屏幕。 以下是详细信息屏幕当前的样子: 这是一个带有标题的UICollectionViewController 。 标题包含2个UILabel对象和一个UITextView对象。 这些对象的布局由一个垂直的UIStackView来pipe理。 UIView用于设置白色背景。 我在运行时定义这个UICollectionReusableView的高度有一些困难。 任何意见表示赞赏。

插入到包含页脚的UICollectionView部分的问题

我有一个典型的UICollectionView,它以垂直方式使用UICollectionViewFlowLayout。 我正在使用分页API来填充集合视图。 为了触发下一个页面的下载,我在使用委托时要求页脚布局: – (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{ RDLoadMoreReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"RDLoadMoreReusableView" forIndexPath:indexPath]; view.delegate = self; [view start]; [self loadNextPageOfAssets]; return view; } 这里是我的loadNextPageOfAssets背后的代码: -(void)loadNextPageOfAssets{ __weak RDRadiusGridViewController *weakSelf = self; // Increment page and request assets. They are added to cluster.assets before the completion block is called. self.cluster.pagination.page++; [self.cluster requestAssetsWithCompletionBlock:^(NSArray […]

没有UICollectionViewLayoutAttributes实例为-layoutAttributesForSupplementaryElementOfKind:

标题是我得到的错误,我不知道为什么,但这里有一些信息,所以希望有人在这里可以澄清我。 我已经分类了UICollectionViewFlowLayout因为这节省了我在UICollectionViewFlowLayout为单元格自己计算框架(也许这是一个问题?)。 然后,我使用UICollectionViewLayoutAttributes信息来计算一个补充的视图,放置它,我得到我想要的布局。 我使用performBatchUpdates:completion:添加,删除和更新视图。 插入工作正常,但是删除项目出现在标题中显示的错误。 所以我知道为什么错误发生,但我不知道为什么它应该发生 。 用一个例子来说明导致这个问题的场景 从1个项目开始,1个补充视图1个部分 添加两个项目( prepareLayout看3个项目与3补充意见) 删除项目( prepareLayout看到2个视图和2个补充视图) layoutAttributesForSupplementaryViewOfKind:atIndexPath:被调用时要求索引path的属性与部分:0和项目:2 崩溃,因为它要求第三个补充视图的属性,即使早些时候它叫做准备布局设置2个项目和2个补充视图 举手投降,绝望 所以,我所知道的有问题的function是: – (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath { return self.layoutInfo[elementKind][indexPath]; } 这当然是由UICollectionView的内部networking自动调用,所以我不知道为什么它要求在该索引path的补充视图。 任何人有任何想法? 也许这是我如何使用performBatchUpdates:completion:但删除工作正常,直到添加补充意见。 我可以根据需要提供更多的代码/解释。

添加一个简单的UIView作为UICollectionView的头

我有一个UICollectionView 。 我想添加一个标题。 我的标题只会是一个UILabel 。 我有 : 1)在IB中select“部分标题”作为收集视图附件。 2)在IB中创build了一个集合可重用视图,声明为collectionViewHeader 。 3)添加这些行: – (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { if (kind == UICollectionElementKindSectionHeader) { return collectionViewHeader; } return nil; } 但他们从来没有被称为。 我是否必须为该标签创build一个类才能使用 [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"]; ? 为什么不像UITableView那样简单,只需拖放任何你想要的标题? 事情是如此复杂的UICollectionView …

UICollectionReusableView – 缺less函数返回

考虑到UICollectionView的头部,我有一个奇怪的问题。 我基本上使用的代码: http : //www.raywenderlich.com/78551/beginning-ios-collection-views-swift-part-2 func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView { let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "dd.MM.yyyy' – 'HH:mm'" //1 switch kind { //2 case UICollectionElementKindSectionHeader: //3 let h = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "eventHeaderView", forIndexPath: indexPath) as eventHeader h.eventFirstline.text = "First Line" h.eventSecondline.text = thisEvent.eventName h.eventDate.text = dateFormatter.stringFromDate(thisEvent.startDate) h.eventDescription.text […]

UICollectionView自定义行分隔符

我想为我们的新应用程序在UICollectionView 2pt黑色分隔符 。 下面是我们应用的屏幕截图。 我们不能使用UITableView ,因为我们有自定义的插入/删除animation,滚动和视差效果等等。