Hi,
I am testing my master-detail view app on iPad (simulator). I found that the large title can show in the master view controller, but it is not working correctly in the detail view controller, meaning there cannot be two large titles on master and detail view controller at the same time. On iPhone they work perfectly so it is iPad-only issue.
I set navigationController.navigationBar.prefersLargeTitles = true and navigationItem.largeTitleDisplayMode = .always in the scenedelegate.swift and detailviewcontroller.swift respectively:
scenedelegate.swift
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let window = window else { return }
guard let splitViewController = window.rootViewController as? UISplitViewController else { return }
guard let navigationController = splitViewController.viewControllers.last as? UINavigationController else { return }
splitViewController.preferredDisplayMode = .allVisible
navigationController.navigationBar.prefersLargeTitles = true
splitViewController.delegate = self
}
detailviewcontroller.swift
import UIKit
class DetailViewController: UIViewController {
let detailLabel: UILabel = {
let label = UILabel()
label.text = "home"
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
override func viewDidLoad() {
super.viewDidLoad()
setupLayout()
}
func setupLayout(){
navigationItem.title = "Home"
navigationItem.largeTitleDisplayMode = .always
view.addSubview(detailLabel)
view.backgroundColor = UIColor.systemBackground
NSLayoutConstraint.activate([
detailLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor),
detailLabel.centerYAnchor.constraint(equalTo: view.centerYAnchor),
])
}
}
Any idea how can I fix this? Thanks!