我是初学者,我想知道如何添加为 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/