I have a UITableView embedded in a UINavigationController. The UITableView is set up as follows:
import UIKit
class HistoryTableViewController: UITableViewController {
let cellID = "HistoryColumns"
struct CellData {
let date: String?
let number: String?
let before: String?
let after: String?
let diff: String?
let strength: String?
let location: String?
}
var data = [CellData]()
override func viewDidLoad() {
super.viewDidLoad()
data = [
// data goes here
]
tableView.register(HistoryTableViewCell.self, forCellReuseIdentifier: cellID)
self.navigationController?.navigationBar.topItem?.title = "Recent Activity"
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellID) as! HistoryTableViewCell
if indexPath.row % 2 == 0 {
cell.backgroundColor = UIColor.orange.withAlphaComponent(0.3)
}
cell.date.valueLabel.text = data[indexPath.row].date
cell.number.valueLabel.text = data[indexPath.row].flightNumber
cell.before.valueLabel.text = data[indexPath.row].preFuel
cell.after.valueLabel.text = data[indexPath.row].postFuel
cell.diff.valueLabel.text = data[indexPath.row].uplift
cell.strength.valueLabel.text = data[indexPath.row].density
cell.location.valueLabel.text = data[indexPath.row].location
return cell
}
}
I call the controller within a UINavigationController as follows:
@objc func handleTap(_ sender: UITapGestureRecognizer? = nil) {
DispatchQueue.asyncMain {
let history = HistoryTableViewController()
let navigationController = UINavigationController(rootViewController: history)
self.present(navigationController, animated: true, completion: nil)
}
}
What I want to do is to define the height of the navigationController's view here (around 500). I've tried using navigationController.view.heightAnchor.constraint but it had no effect (obviously I set translatesAutoresizingMaskIntoConstraints to false first)...
I do want to use a UINavigationController here because I need the navbar that comes with it. Any suggestions greatly appreciated...