0

I'm quite new in swift programming but couldn't find an answer to the question how to change the title of the navigation bar when the user taps on it (see example app "ToDo" from Microsoft [former Wunderlist]). So first I choose the "Item A" out of a tableview and in the following screen the title stands in the navigation bar - so far so good. With a tap on this title "Item A" it should be possible to change the title (also for the previous tableview with the list of items by saving the changes in Realm). For now I just use the commands

title = selectedItem!.title

in my viewDidLoad in the upcoming view controller where .title equals the title from my "Item"-class

class Item: Object {
   var parentCatergory = LinkingObjects(fromType: Category.self, property: "items")
   @objc dynamic var title: String = ""
}

Any ideas? Or do I have to use a customized navigation bar, if so how? Thanks in advance!

1 Answers1

0

According to the UIViewController lifecycle, anything that you add to the method viewDidLoad() will be executed once when the view is loaded. If you want to change the title property on demand on a ViewController, is necessary invoke the navigation bar title property again from your tab action method. Check this post for more information: How to set the title of a Navigation Bar programmatically?

Pedro Trujillo
  • 1,559
  • 18
  • 19