问题
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.
回答1:
I can't think of a good reason to do this but...
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)
Where numOfItems.count
is the number of cells you have.
来源:https://stackoverflow.com/questions/35189482/swift-dynamic-tableview-height-based-on-content