【问题标题】:Use a function builded for UICollectionView inside the function UITableView heightForRowAt (Swift)在函数 UITableView heightForRowAt (Swift) 中使用为 UICollectionView 构建的函数
【发布时间】:2018-04-25 08:08:02
【问题描述】:

我是初学者,我想知道如何添加这个为 UICollectionView 创建的函数

func heightForAnnotationAtIndexPath(indexPath: IndexPath, withWidth width: CGFloat) -> CGFloat {

        let place = places[indexPath.row]
        let annotationPadding = CGFloat(5)

        let font = UIFont.systemFont(ofSize: 15)
        let commentHeight = place.heightForComment(font, width: width)

        let height = annotationPadding + commentHeight + annotationPadding

        return height
    }

里面

 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {


    return 130
}

因为与 tableView 中的 collectionView 不同,我只需要高度值,因为没有列

【问题讨论】:

    标签: ios swift uitableview swift3 uicollectionview


    【解决方案1】:

    我现在无法访问我的 Mac,但为什么不在 tableView() 函数中返回 heightForAnnotationAtIndexPath() 函数呢?我的想法如下:

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    
        //you'll have to set your indexPath and withWidth parameters
        return heightForAnnotationAtIndexPath(indexPath, withWidth)
    
    }
    

    他们都为你返回 CGFloats,所以这应该对你有用。

    【讨论】:

      猜你喜欢
      • 2021-07-11
      • 2015-04-17
      • 2020-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-03
      相关资源
      最近更新 更多