Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prefersLargeTitles doesn't work with programmatic layout

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.

like image 702
Ivan Smetanin Avatar asked Jan 19 '18 20:01

Ivan Smetanin


1 Answers

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
like image 91
Mark Suman Avatar answered Oct 12 '22 14:10

Mark Suman