1

I am trying to have a navigation controller with different preferlargetitles booleans on my main page and another storyboard. When I start the simulation it lands on the main page with large title true. Then I tap on a collection view cell to view a pdf and I have the large title set to false for that view controller (or so I believe). When I press the back button on the nav controller to the main page, the large title is now set to false.

I have tried to set the large title to true in the collectionview viewDidLoad but nothing.

Code for the main page on going to the pdf view controller:

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let selectedRow = indexPath.row
        if selectedRow == 0 {
            print("add button selected")
            return
        }
        else {
            let document = Data.documentModel[selectedRow - 1]
            let storyboard = UIStoryboard(name: String(describing: NoteTakingViewController.self), bundle: nil)
            let vc = storyboard.instantiateInitialViewController() as! NoteTakingViewController
            vc.document = document
            //self.present(vc, animated: true, completion: nil)
            self.show(vc, sender: selectedRow)
        }

Code for inside the pdf view controller after you tap on a file from the main page:

override func viewDidLoad() {
        super.viewDidLoad()
        ....(to view the pdf code went here)
        self.title = document.title
        navigationController?.navigationBar.prefersLargeTitles = false
        // Do any additional setup after loading the view.
    }

When I go to the storyboard I get the small title but it carries over to the main page.

Revanth Kausikan
  • 673
  • 1
  • 9
  • 21
moaster
  • 33
  • 4

2 Answers2

0

Write this line of code in your main view controller, by this when ever you will come to this view controller title will be set to large, now you can remove from the viewdidLoad

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated) // No need for semicolon
     navigationController?.navigationBar.prefersLargeTitles = true
}
Zeeshan Ahmed
  • 834
  • 8
  • 13
  • Thank you that worked! So the viewWillAppear function is called when the view controller comes back to the screen after it has already been loaded. Is there any resources you suggest that I should read up on for this because I would like to make it now so that when you go back to the main view controller it doesn't have the small titles then makes it a large title. When you go back the large title is already set for when it comes back on the screen. – moaster Apr 16 '19 at 05:08
  • viewWillAppear calls up every time VC appears, you can also put the code into viewwilldisappear of the other VC from where you come back to the main vc – Zeeshan Ahmed Apr 16 '19 at 05:10
0

In the navigation bar in storyboards, Prefers Large Titles unchecked.

In your View Controller where you have to use large Title:

self.navigationController?.navigationBar.prefersLargeTitles = true
Ravindra_Bhati
  • 1,071
  • 13
  • 28