基于内容的 Swift 动态 tableview 高度

编程入门 行业动态 更新时间:2024-10-25 12:21:39
本文介绍了基于内容的 Swift 动态 tableview 高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

进行了搜索,我在这里唯一能找到的是动态单元格高度.我是 swift 的新手,我想要一个 tableview,tableview 的高度根据行数进行调整.预先感谢您的帮助.

Did a search and the only thing I can find on here are for dynamic cell heights. I'm new to swift, and I'd like to have a tableview where the height of the tableview adjusts according to the number of rows. Thanks in advance for the help.

推荐答案

我想不出这样做的充分理由,但是...

I can't think of a good reason to do this but...

您必须知道 tableview 中有多少项,因为它是您的数据源(大概是您在 collectionView:numberOfItemsInSection 中返回的任何数字.

You must know how many items are in the tableview since it's your datasource (presumably whatever number you're returning in collectionView:numberOfItemsInSection.

所以你可以像这样调整大小:

So you could adjust the size like so:

let totalSizeOfCells = (tableView.rowHeight * CGFloat(numOfItems.count))
tableView.frame = CGRectMake(0, 0, self.view.frame.width, totalSizeOfCells)

其中 numOfItems.count 是您拥有的单元格数量.

Where numOfItems.count is the number of cells you have.

这篇关于基于内容的 Swift 动态 tableview 高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 11:05:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1408805.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:高度   内容   动态   tableview   Swift

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!