【问题标题】:Table view cell size for horizontal UICollectionView within a UITableViewUITableView 中水平 UICollectionView 的表格视图单元格大小
【发布时间】:2023-04-04 23:36:01
【问题描述】:

我在UITableView 中设置了多个水平滚动的UICollectionView(s),所以我可以垂直滚动。

我遇到的一个问题是,表格视图的行高在我知道它们应该有多高之前被调用(我希望每个 UICollectionView 的整个高度都填充表格视图单元格)。

我该如何解决这个问题?

【问题讨论】:

    标签: uitableview ios8 uicollectionview


    【解决方案1】:

    我的建议是为集合视图创建自定义布局。然后它可以计算单元格大小并在集合视图调整大小时得到通知。

    【讨论】:

    • 这是如何传递到表格视图的?您能否提供更多详细信息(即代码示例)?
    【解决方案2】:

    使用此函数,您可以确定您拥有的collectionView 的高度。

    aCollectionView.collectionViewLayout 属性上调用collectionViewContentSize 并以CGSize 的形式获取内容的高度和宽度。

    -(CGFloat)collectionViewHeight
    {
      [collectionView layoutIfNeeded];
    
      return [collectionView contentSize].height;
    }
    

    【讨论】:

    • 这是如何传递到表格视图的?您能否提供更多详细信息(即代码示例)?
    【解决方案3】:

    为您的身高创建一个变量,并在您的heightForRowAtIndexPath 方法中返回该变量。一旦你弄清楚你的身高,然后重新加载你的 tableView。

    var height: CGFloat = 44
    
    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return height
    }
    
    func something() {
    
        height = 1234//Or whatever your height should be
        self.table.reloadData()
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-08
      • 2015-04-07
      • 2017-06-09
      • 2013-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多