ios - 在函数 UITableView heightForRowAt (Swift) 中使用为 UICollectionView 构建的函数

标签 ios swift uitableview swift3 uicollectionview

我是初学者,我想知道如何添加为 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 不同,我只需要高度值,因为没有列

最佳答案

我现在无法访问我的 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,所以这应该对您有用。

关于ios - 在函数 UITableView heightForRowAt (Swift) 中使用为 UICollectionView 构建的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47250838/

相关文章:

ios - 为什么不能为字典条目分配新值?

ios - 选择 iOS 测试框架

ios - SwiftUI macos NSWindow 实例

swift - 检查用户是否点击了外部 View Controller

ios - 将 distanceFromLocation 转换为 Int

iphone - 像foursquare或gowalla这样的应用程序是如何实现他们的签到功能的?

ios - 在 Storyboard 中,UIViewController 的宽度不是 iPhone 的宽度

objective-c - 试图将 RowAtIndexPath 移动到另一个部分,iOS

ios - 通过两个不同的带部分的 NSFetchedResultsControllers 的单 TableView

ios - 如何在输入最少字符后显示搜索结果表?