Ios 未定义UICollectionViewFlowLayout的行为

Ios 未定义UICollectionViewFlowLayout的行为,ios,objective-c,autolayout,uicollectionview,uicollectionviewlayout,Ios,Objective C,Autolayout,Uicollectionview,Uicollectionviewlayout,我有一个集合视图,它被设置为一个水平的单元格行。它抛出以下约束错误(我使用的是自动布局): 未定义UICollectionViewFlowLayout的行为,因为项目高度必须小于UICollectionView的高度减去部分插入的顶部和底部值,减去内容插入的顶部和底部值 我在谷歌上搜索了一下,大家都认为只要覆盖UIScrollViewDelegate方法就可以解决这个问题: - (CGSize)collectionView:(UICollectionView *)collectionView l

我有一个集合视图,它被设置为一个水平的单元格行。它抛出以下约束错误(我使用的是自动布局):

未定义UICollectionViewFlowLayout的行为,因为项目高度必须小于UICollectionView的高度减去部分插入的顶部和底部值,减去内容插入的顶部和底部值

我在谷歌上搜索了一下,大家都认为只要覆盖UIScrollViewDelegate方法就可以解决这个问题:

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    // iPhone 6+ device width handler
    CGFloat multiplier = (screenWidth > kNumberOfCellsWidthThreshold) ? 4 : 3;
    CGFloat size = screenWidth / multiplier;
    return CGSizeMake(size, size);
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 0, 0, 0);
}
但它仍然不起作用。尽管我将单元格设置为与容器相同的高度,但它似乎对单元格高度高于其容器的事实感到惊讶。下面是错误的其余部分:

相关的UICollectionViewFlowLayout实例是UICollectionViewFlowLayout:0x7fa6943e7760,它附加到MyCollectionView:0x7fa69581f200;baseClass=UICollectionView

帧=(0;375 98);clipsToBounds=是;自动调整大小=RM+BM; 层=层:0x7fa694315a60;contentOffset:{0,0};contentSize:{0,134}


手动将单元格设置为更小的大小(例如,
size-50.0
似乎可行,但为什么我不能将单元格大小设置为与其容器相同的高度?

我的问题中缺少的一点是,这个
UICollectionView
嵌套在
UITableView
中。iOS 8引入了
layoutMargins
来代替内容偏移值

根据这一问题:

我必须覆盖包含表视图的单元格边距:

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Remove seperator inset
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }

    // Prevent the cell from inheriting the Table View's margin settings
    if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
        [cell setPreservesSuperviewLayoutMargins:NO];
    }

    // Explictly set your cell's layout margins
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

覆盖单元的swift

override func awakeFromNib() {
    super.awakeFromNib()
    self.separatorInset = .zero
    self.preservesSuperviewLayoutMargins = false
    self.layoutMargins = .zero
}

你能添加屏幕截图吗?你得到了什么错误,你的视图看起来如何?你需要什么?@iOS_DK我已经在问题中添加了错误;如果你愿意,我会添加一个集合视图的示例,但它不会告诉你比我已经提供的更多的东西。OP提到了CollectionView,但答案是针对TableView。Re答案是ad。CollectionView嵌套在TableView中。