Home > Enterprise >  Adding a prototype cell to a table view in storyboard makes navigation bar title small
Adding a prototype cell to a table view in storyboard makes navigation bar title small

Time:05-22

I have a View Controller which segues from a previous controller that has large titles. The navigation bar in the navigation controller has the Prefers Large Titles checkbox checked.

I have added a Table View to this new view controller. Until then, the title remains large. However as soon as I add prototype cells to the table view, the navigation bar becomes small.

In code I added this:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(true)
    navigationController?.navigationBar.prefersLargeTitles = true
}

The problem is, when the view controller comes into view, the title appears small for a second and then immediately shifts to large title.

How can I fix it so that it appear large as I segue and avoid that size shift once the title becomes visible?

CodePudding user response:

it is a feature: when the user scroll, the large Title will disappear and show small title on top.

your problem happend because in the xib file: your layout is small title and its change to largeTitle when it pushed. but the view doesn't know that.

to fix this you just need to call: view.layoutIfNeeded() in the viewDidLoad() method.

override func viewDidLoad() {
    super.viewDidLoad()
    title = "Large title"
    view.layoutIfNeeded()
}
  • Related