相关疑难解决方法(0)

添加一个简单的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万
查看次数

在Interface Builder中设计UITableView的节头

我有一个xib文件UITableView,我想使用委托方法添加自定义节标题视图tableView:viewForHeaderInSection:.有没有可能设计它Interface Builder,然后以编程方式更改它的一些子视图的属性?

UITableView有更多的章节标题,以便创建一个UIViewInterface Builder和返回这是行不通的,因为我不得不重复它,但没有做任何好的方法.归档和取消归档它不适用于UIImages所以UIImageViews会显示空白.

此外,我不想以编程方式创建它们,因为它们太复杂,结果代码很难读取和维护.

编辑1:这是我的tableView:viewForHeaderInSection:方法:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    if ([tableView.dataSource tableView:tableView numberOfRowsInSection:section] == 0) {
        return nil;
    }

    CGSize headerSize = CGSizeMake(self.view.frame.size.width, 100);

    /* wrapper */

    UIView *wrapperView = [UIView viewWithSize:headerSize];

    wrapperView.backgroundColor = [UIColor colorWithHexString:@"2670ce"];

    /* title */

    CGPoint titleMargin = CGPointMake(15, 8);

    UILabel *titleLabel = [UILabel labelWithText:self.categoriesNames[section] andFrame:CGEasyRectMake(titleMargin, CGSizeMake(headerSize.width - titleMargin.x * 2, 20))]; …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c interface-builder uitableview ios

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