0

I tried to change the title of the page when I get group data from parent view in 3 ways but it didn't change the title

var group : Group? {
    didSet{
        self.navigationItem.title = "from code"
        self.navigationController?.navigationItem.title = "from code"
        self.title = "from code"
    }
}
Dot Freelancer
  • 4,083
  • 3
  • 28
  • 50

1 Answers1

0

You are probably setting the title before the view of the view controller is instantiated. That's why it isn't changing. You must do view related stuff within or after viewDidLoad method of the view controller. For a better understanding of the life cycle of UIViewController see this thread.

Adeel Miraj
  • 2,472
  • 3
  • 22
  • 32
  • The `navigationItem` has nothing to do with `UIViewController.view` and it is often needed before the `view` is used. – Sulthan Sep 23 '17 at 15:46
  • @Sulthan so what do you think is the problem? – Dot Freelancer Sep 23 '17 at 19:05
  • @dotfreelancer Hard to say without seeing the actual code. – Sulthan Sep 23 '17 at 19:22
  • nothing there except the attached code + viewDidLoad func. that's why i think the @Adeel answer is reasonable! – Dot Freelancer Sep 23 '17 at 19:31
  • I'm also wondering why you can't set the title of the view controller inside the didSet method. view of the view controller gets instantiated 'before' the didSet method is called so I think this answer is not to be taken seriously. – Junsu Kim Aug 17 '21 at 12:20