0

Simple question but I couldn't find any solution. I want to push new ViewController with NavigationController In vc1 I have title "xxx" and I am pushing to vc2

let vc2 = MyViewController()
navigationController?.pushViewController(vc, animated: true)

I want vc2 to have the same title as vc1 but without the changing title animation when vc2 is being pushed

Adam
  • 1,776
  • 1
  • 17
  • 28
  • You have to set it in VC2. https://developer.apple.com/documentation/uikit/uinavigationcontroller?language=objc#topics "The Middle Item" You can also try: https://stackoverflow.com/questions/24543702/animate-nav-bar-title-text-change – sloik May 29 '18 at 18:45

2 Answers2

1

First: You have to create a super view controller and set the title like this

   class MainViewController: UIViewController {

            override func viewDidLoad() {
                super.viewDidLoad()
                self.title = "Commmon name"

            }
    }

Second: Inherit super view controller in every view controller where you want to same Title or every this which you want same in every view controller.

class FirstViewController: MainViewController {

        override func viewDidLoad() {
            super.viewDidLoad()

        }
}

class SecondViewController: MainViewController {

        override func viewDidLoad() {
            super.viewDidLoad()

        }
}

Now you can push then you will get same title in every view controller which one is inherit super view controller like above example

Jogendar Choudhary
  • 3,476
  • 1
  • 12
  • 26
0

you can set same title in two controllers, for example:

class VcOne : UIViewController{
    override func viewDidLoad() {
            super.viewDidLoad()
            self.title = "Title"
        }
}

class VcTwo : UIViewController{
    override func viewDidLoad() {
            super.viewDidLoad()
            self.title = "Title"
        }
}

hope it can help you

bobo pei
  • 52
  • 1
  • 10