WepsTech
The world of development
Hey, Guys I hope you are looking for the height adjustment of the tableview in swift. If Yes, They you are on the right place. In this tutorial, I have given the complete and very easy demonstration about the UITableviewHeight adjustment of the as per content size. And while you are going through with this process check carefully every point. Check the demonstration till the end. I hope you will get the answer of your question. Video Link
able views in iOS display rows of vertically scrolling content in a single column. Each row in the table contains one piece of your app’s content. You can configure a table to display a single long list of rows, or you can group related rows into sections to make navigating the content easier. More information
The relationship between two user interface objects that must be satisfied by the constraint-based layout system. Read more on Apple Developer Docs
// // ViewController.swift // TableView // // Created by Pushpendra Kumar on 03/04/22. // import UIKit class ViewController: UIViewController { @IBOutlet weak var tableView: UITableView! @IBOutlet weak var tableViewHeight: NSLayoutConstraint! private var itemList : [String] = [String]() override func viewDidLoad() { super.viewDidLoad() self.setTableView() } private func setTableView(){ self.tableView.delegate = self self.tableView.dataSource = self self.tableView.register(UINib(nibName: "TableViewCell", bundle: nil), forCellReuseIdentifier: "TableViewCell") self.setTabeleViewData() } override func viewWillLayoutSubviews() { self.tableViewHeight.constant = self.tableView.contentSize.height } private func setTabeleViewData(){ for i in 0...10 { self.itemList.append("Some content at the particular index \(i + 1)") } self.tableView.reloadData() self.tableView.invalidateIntrinsicContentSize() } } extension ViewController : UITableViewDataSource, UITableViewDelegate { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return self.itemList.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell", for: indexPath) as! TableViewCell cell.lbDescription.text = self.itemList[indexPath.row] return cell } }
Complete code for demo. And also watch the complete video for more and deep understanding.
Learn more on wepstech.com