标签: uicollectionreusableview

如果节标题隐藏在UICollectionView中,则删除空白空间

我有两个部分UICollectionView.我想UICollectionView仅显示第1节中的节标题.不在第0部分.

于是,我就回nilviewForSupplementaryElementOfKind:方法section == 0并返回查看的section == 1.

它崩溃并显示以下错误:

Assertion failure in -[UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes]:
Run Code Online (Sandbox Code Playgroud)

这是补充视图的代码.

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    UICollectionReusableView *sectionHeader = nil;
    if (kind == UICollectionElementKindSectionHeader && indexPath.section == 1) {
        sectionHeader = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"EventSectionHeader" forIndexPath:indexPath];
        sectionHeader.layer.borderWidth = .5f;
        sectionHeader.layer.borderColor = [UIColor colorWithRed:221.0 / 255.0 green:223.0 / 255.0 blue:220.0 / 255.0 alpha:1.0].CGColor;
    }

    return sectionHeader;
}
Run Code Online (Sandbox Code Playgroud)

我发现在viewForSupplementaryElementOfKind:方法崩溃时也会返回nil .其他答案建议删除该方法.

但我想只显示特定部分的节标题.如何只为一个部分实现返回视图?谢谢.任何帮助,将不胜感激.

编辑:

正如@san所说,我已更新代码以隐藏节标题.有用.它隐藏了标题.但我仍然看到节标题处的空白空间.预期结果是如果隐藏了节标题,则应该没有空格. …

iphone ios uicollectionview uicollectionreusableview ios7

40
推荐指数
3
解决办法
3万
查看次数

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

我有一个UICollectionView.我想添加一个标题.我的标题只是一个UILabel.我有 :

1)在IB中选择"Section Header"作为Collection View附件.

2)在IB中创建了一个Collection Reusable View,在旁边,声明为collectionViewHeader.

3)添加这些行:

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    if (kind == UICollectionElementKindSectionHeader) {

            return collectionViewHeader;
    }
    return nil;
}
Run Code Online (Sandbox Code Playgroud)

但它们永远不会被称为.

我是否必须为该标签创建一个类才能使用

[self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
Run Code Online (Sandbox Code Playgroud)

为什么它不像UITableView你拖放你想要的任何标题那样简单?!事情是如此复杂UICollectionView......

header ios uicollectionview uicollectionreusableview

31
推荐指数
2
解决办法
6万
查看次数

使用iOS UICollectionView仅允许某些部分的标题视图

下面的代码正确显示我的标题视图,但是对于UICollectionView中的每个部分:

-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView
          viewForSupplementaryElementOfKind:(NSString *)kind
                                atIndexPath:(NSIndexPath *)indexPath {
    UICollectionReusableView * headerView =
        [collectionView 
            dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader 
                               withReuseIdentifier:@"SectionHeaderCollectionReusableView"
                                      forIndexPath:indexPath];
    switch (indexPath.section) {
        case Section_One:
            return headerView;
        case Section_Two:
            return headerView;
        case Section_Three:
            return headerView;
        case Section_Four:
            return headerView;
        case Section_Five:
            return headerView;

        default:
            return headerView;
    }
}
Run Code Online (Sandbox Code Playgroud)

我想要做的是,不显示'Section_One'或'Section_Two'的标题视图,但返回'nil'会导致'NSInternalInconsistencyException':

-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView
          viewForSupplementaryElementOfKind:(NSString *)kind
                                atIndexPath:(NSIndexPath *)indexPath {
    UICollectionReusableView * headerView =
        [collectionView 
            dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader 
                               withReuseIdentifier:@"SectionHeaderCollectionReusableView"
                                      forIndexPath:indexPath];
    switch (indexPath.section) {
        case Section_One:
            return nil;
        case Section_Two:
            return nil;
        case Section_Three:
            return headerView;
        case Section_Four:
            return …
Run Code Online (Sandbox Code Playgroud)

objective-c ios uicollectionview uicollectionreusableview

30
推荐指数
3
解决办法
2万
查看次数

UICollectionView自定义行分隔符

我想使二点黑色隔板UICollectionView为我们的新的应用程序.我们的应用程序截图如下.我们无法使用UITableView,因为我们有自定义插入/删除动画,滚动和视差效果等.

例

objective-c ios uicollectionview uicollectionviewlayout uicollectionreusableview

19
推荐指数
3
解决办法
3万
查看次数

16
推荐指数
3
解决办法
9159
查看次数

UICollectionReusableView - 函数中缺少返回

考虑到标题,我遇到了一个奇怪的问题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 = thisEvent.shortDescription

                return h
            default:
                //4
                assert(false, "Unexpected element kind")
            }
    }
Run Code Online (Sandbox Code Playgroud)

当即时部署到模拟器或真实设备时,所有这些都可以正常工作,但奇怪的是,当我想为测试目的构建Ad-Hoc包时,它告诉我

在期望返回'UICollectionReusableView'的函数中缺少返回

好的,到目前为止一切都很好,切换机箱外没有任何东西,所以它什么都不返回 - 但是为什么它只在我试图建立一个包时才给出"热部署"的任何警告?

ios uicollectionview uicollectionreusableview swift

14
推荐指数
1
解决办法
3435
查看次数

更新UICollectionView的标题内容而不重新加载整个部分

我想动态更新我的UIColectionView中的标题信息的内容,但我不想重新加载整个部分,因为我经常这样做.

优雅解决方案的任何想法?

谢谢

objective-c ios uicollectionview uicollectionreusableview

11
推荐指数
1
解决办法
5500
查看次数

viewForSupplementaryElementOfKind未在自定义UICollectionViewLayout上调用

我创建了一个自定义的UICollectionViewLayout,并将它放在故事板中的Collection View Controller中.我在显示项目/单元格时没有遇到太多问题.我的问题是没有调用viewForSupplementaryElementOfKind.我似乎无法确定为什么会这样.我试图回到默认布局,它确实调用它,但我需要我的自定义UICollectionViewLayout.我已经离开了NSLogs来检查并且没有调用viewForSupplementaryElementOfKind.

这是我的MyCollectionViewController.m

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
viewArray = [NSMutableArray array];

//setup the delegate for vertical flow layout
[(VerticalFlowLayout*)self.collectionViewLayout setDelegate:self];

//register the headers
[self.collectionView registerNib:[ButtonHeaderCollectionReusableView nib] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:[ButtonHeaderCollectionReusableView reusableID]];

//set the insets
[self.collectionView setContentInset:UIEdgeInsetsMake(23, 5, 10, 5)]; }

#pragma mark - CollectionView DataSource

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [self.cardsArray count];
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
NSLog(@"Number of Sections");

return 1;
}

-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

NSLog(@"Making Card");

CardCell *card …
Run Code Online (Sandbox Code Playgroud)

objective-c ios uicollectionview uicollectionviewlayout uicollectionreusableview

11
推荐指数
2
解决办法
9532
查看次数

UICollectionView和自定义UICollectionReusableView不起作用

我正在尝试UICollectionReusableViewUICollectionView标题中使用自定义(具有自己的类和XIB).但是在获取标题后的数据后,我什么都没有.

我的步骤:

  1. viewDidLoad中注册类:

     [self.collectionView registerClass:[CollectionViewHeader class] 
      forSupplementaryViewOfKind: UICollectionElementKindSectionHeader 
      withReuseIdentifier:@"HeaderView"];
    
    Run Code Online (Sandbox Code Playgroud)
  2. 试图显示:

    - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
    {
    UICollectionReusableView *reusableView = nil;
    
    if (kind == UICollectionElementKindSectionHeader) {
        CollectionViewHeader *collectionHeader = [self.collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
    
        NSInteger section = [indexPath section];
        id <NSFetchedResultsSectionInfo> sectionInfo = [fetchRecipes sections][section];
        collectionHeader.headerLabel.text = @"bla-bla-bla";
    
        reusableView = collectionHeader;
    }
    
    return reusableView;
    }
    
    Run Code Online (Sandbox Code Playgroud)

谁能告诉我什么是错的?)感谢您的任何建议

xib ios uicollectionview uicollectionreusableview

10
推荐指数
2
解决办法
2万
查看次数

检测iOS UICollectionCell何时离开屏幕

我有一个UICollectionView将图片作为其数据存储区中的元素.

我想将高分辨率pic加载到元素中,只有当它的对应UICollectionViewCell当前显示在屏幕上时.之后,当UICollectionViewCell屏幕关闭时,我想将元素返回UIImage到低分辨率版本.

我的问题是,如何检测UICollectionViewCell屏幕何时关闭?

(我尝试使用该prepareForReuse方法,但我无法预测何时会被调用).

我目前正在使用一段代码,scrollViewDidScroll每次视图滚动时我都会检查self.collectionView.visibleCells以查看哪些单元格已在屏幕上滚动.

这看起来有点开销,我想知道UICollectionViewCell在滚动屏幕的时候是否有自己调用的方法?

ios uicollectionview uicollectionviewcell uicollectionreusableview

10
推荐指数
2
解决办法
6065
查看次数