I'm trying to add a table view programmatically, but large title doesn't show.
Here is my code:
self.view.addSubview(module.tableView)
module.view.translatesAutoresizingMaskIntoConstraints = false
if #available(iOS 11.0, *) {
NSLayoutConstraint.activate([
module.view.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor, constant: 0),
module.view.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor, constant: 0),
module.view.leadingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.leadingAnchor, constant: 0),
module.view.trailingAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.trailingAnchor, constant: 0)
])
}
Note: large titles enabled in view controller
if #available(iOS 11.0, *) {
navigationController?.navigationBar.prefersLargeTitles = true
navigationItem.largeTitleDisplayMode = .always
}
Maybe it's important: I'm trying to add a table as a child view controller. My child controller is a UITableViewController. And if I add child view in viewDidLoad()
large title shows but doesn't scroll.
Here is the link to file where I'm adding my child module. Detail code you can see in question or here in addChild(module:)
method.
Let me know how to fix this bug please.
I'm using a programmatic layout and ran into a similar issue. I found the solution here: https://stackoverflow.com/a/46692583/131378. In viewDidLoad()
I had to toggle the largeTitleDisplayMode
off and on again. That was the correct combination that got the large titles working with scrolling:
self.navigationItem.largeTitleDisplayMode = .never
self.navigationItem.largeTitleDisplayMode = .always
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With