7

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.

Ivan Smetanin
  • 1,999
  • 2
  • 21
  • 28

5 Answers5

2

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
Mark Suman
  • 10,430
  • 2
  • 27
  • 23
1

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
}
Rafał Sroka
  • 39,540
  • 23
  • 113
  • 143
  • I've enabled this – Ivan Smetanin Jan 19 '18 at 20:21
  • 1
    Thanks. How is adding a table view connected with large titles? Does the large title work without the table related code? – Rafał Sroka Jan 19 '18 at 20:24
  • Large title work without table(just showing large state). If I'm adding table view in storyboard all works perfect. Maybe it's important: I'm trying to add a table as a child view controller – Ivan Smetanin Jan 19 '18 at 21:20
  • 1
    Can you post the code where you're adding it as a child? – Rafał Sroka Jan 19 '18 at 21:21
  • Of course. Here is the [link to file](https://github.com/ismetanin/Notty/blob/categories_adding/Notty/User%20Stories/Categories/Configurator/CategoriesModuleConfigurator.swift) where I'm adding my child module. Detail code you can see in question or [here](https://github.com/ismetanin/Notty/blob/categories_adding/Notty/User%20Stories/Categories/View/CategoriesViewController.swift) in `addChild(module:)` method. – Ivan Smetanin Jan 19 '18 at 21:28
0

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.

dispatchswift
  • 1,046
  • 9
  • 21
  • I do see you have a navigation controller embedded within "Main.storyboard", but with your project setup you need to embed another one within "CategoriesViewController.storyboard". – dispatchswift Jan 27 '18 at 12:31
  • CategoriesViewController is embedded programmatically in AppDelegate and there it is set as root view – Ivan Smetanin Jan 27 '18 at 16:39
  • Whoops! I overlooked that... I've edited my solution. Let me know if it works. – dispatchswift Jan 27 '18 at 21:55
  • New solution doesn't work I see small title :( Maybe it's important: if I add child view in `viewDidLoad()` large title shows but doesn't scroll – Ivan Smetanin Jan 28 '18 at 11:27
  • I checked out your project, and I realized the issue comes into play when `categoriesListModule` is added as a child to the `CategoriesViewController` instance inside of `CategoriesModuleConfigurator.swift`. – dispatchswift Jan 29 '18 at 04:10
  • I've tried to add a table as a child view in `viewDidLoad()` but it didn't work – Ivan Smetanin Jan 29 '18 at 13:40
  • If you update your `Deployment Target`, and comment out adding `categoriesListModule` as a child to `CategoriesViewController`, you'll see the large title. It's not a solution to your current setup, but it will help you narrow down the issue. – dispatchswift Jan 29 '18 at 21:22
0

You have to click your main Navigation Controller on Navigation Bar and then select "Prefers Large Titles" in your Attribute Inspector. enter image description here

Osman
  • 1,496
  • 18
  • 22
0

Try this, the older answers doesn't work! https://developer.apple.com/forums/thread/82213?answerId=662742022#662742022

Mihail Salari
  • 1,471
  • 16
  • 17