0

I have 2 view controllers. Now I want to make a present-segue from one to the other. I made the segue in the storyboard, but performed it in the source code of the first vc. The view which will be shown has this line in the viewDidLoad method:

var font = self.navigationController?.navigationBar.titleTextAttributes![NSAttributedString.Key.font] as! UIFont

When the view loads in the segue there is an exception and I checked that the titleTextAttributes are nil. When I use the show-segue it works, but I don't want this back-button in my navigation bar.

What is my mistake or is there any other solution?

1 Answer 1

1

The problem is that, when you use present, you are simply presenting a ViewControllerB Over a ViewControllerA(Embedded in NavigationController), But as ViewControllerB is having different NavigationController or may not have Navigation Controller, when you present, so you are getting nil there

You can simply remove that line of code and use this

var font = UIFont(name: "Your Font name", size: YOUR_FONT_SIZE)

And do present as your are doing with Segue.

Hope it helps

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! But now the navigation bar isn't shown. Do you know how to solve that?
Embed your ViewControllerB into NavigationController and Present that
I tried that and had another problem, but now I'll just use the show-segue and use navigationItem.hidesBackButton = true. Seems to be the easiest solution

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.