Skip to content

Changing the height of a TableView cell (Swift5.0.1)

   

This is how to change the height of a cell in TableView.
I was able to achieve this by using .rowHeight for batch return and heightForRowAt for individual changes.

https://github.com/takoikatakotako/swiswiswift-ios

alt

import UIKit
class TableViewHeight_20190730: UIViewController {
private var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView = UITableView()
tableView.frame = view.bounds
tableView.register(UITableViewCell.self, forCellReuseIdentifier: NSStringFromClass(UITableViewCell.self))
tableView.dataSource = self
tableView.delegate = self
view.addSubview(tableView)
}
}
extension TableViewHeight_20190730: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 6
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: NSStringFromClass(UITableViewCell.self))! as UITableViewCell
cell.textLabel?.text = "\(indexPath.row)"
cell.textLabel?.textAlignment = .center
return cell
}
}
extension TableViewHeight_20190730: UITableViewDelegate {
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return CGFloat(40 * indexPath.row + 40)
}
}

  1. UIButton, display a button (Swift5.0)
  2. Using UISlider to retrieve a value at regular intervals (Swift5.0)
  3. Getting a value with UISlider (Swift5.0)
  4. Displaying an incoming call screen using CallKit.
  5. Performing UITest (E2E testing) on iOS (Swift5.0)OSでUITest(E2Eテスト)を行う(Swift5.0)
  6. Switch RootViewController with animation (Swift4.2)
  7. Parse a local Json file and display it in table view (Swift4.2)