-1

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...

DevB1
  • 1,235
  • 3
  • 17
  • 43
  • Does this answer your question? [How to increase the height of navigation bar in Xcode?](https://stackoverflow.com/questions/31940352/how-to-increase-the-height-of-navigation-bar-in-xcode) – timbre timbre Jun 22 '20 at 14:46
  • Sorry no it's the actual view itself. I don't want it to take up the entire screen - more like a pop-up – DevB1 Jun 22 '20 at 14:47

1 Answers1

0

When you say .present, the way the presented view controller occupies the screen is up to you. Make a custom transition and supply your own UIPresentationController subclass with an implementation of frameOfPresentedViewInContainerView to say where the presented view controller's view should go.

This is a silly example with a custom animation as well, but you don't have to customize the animation if you don't want to. The important thing is that I've made the presented view controller smaller than it normally would be.

enter image description here

matt
  • 515,959
  • 87
  • 875
  • 1,141