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
Enable large titles in viewDidLoad
method of the view controller where you're configuring the table view.
if #available(iOS 11, *) {
self.navigationController?.navigationBar.prefersLargeTitles = true
}
Update your iOS Deployment Target
to 11.0
or higher. Currently, it's at 10.3
. That's why you don't see the large titles.
Try this, the older answers doesn't work! https://developer.apple.com/forums/thread/82213?answerId=662742022#662742022
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.