0
votes

I have a view controller which has embedded a navigation controller.

From this view controller I am being able to change the title of the navigation bar with navigationItem.title = "title".

Furthermore I have another tableview controller and I want to update the tile of the navigation controller also from here, this tableview controller acts as a Slide Out Menu for the first view controller.

Navigation controller and tableview controller are not connected directly but I use a library called SWRevealViewController to create and connect the slide out menu with first view controller.

I have tried these codes:ViewController().navigationItem.title = "secondTitle"

I have also tried to put the process of changing the title in first controller in function and create an instance like :ViewController().updateNavTitle(), also tried to crete a segues but without any result.

1
UIViewController *vc = [navigationController.viewControllers objectAtIndex:index]; vc.title = @"title"; - Elliot Alderson
actually the code is on swift and I am not familiar with objective-c at all, do u have a solution for swift ? - Ilir V. Gruda
In my app, i can set the title using navigationitem.title or myviewcontroller.title (I use the latter without problems). I have my view controllers as properties in my appdelegate.h file which I can access at any point in my app. I'm not sure what you're asking exactly. I think the title is from the view controller that is displayed by the navigation controller. I just set each view controller's title (self.title = @"title") and when it gets pushed, the title updates. - Elliot Alderson

1 Answers

1
votes

Create a String variable in your first class and access this property in your Slide Out controller and and update it. Now in your first controller's in viewWillAppear method update the title like below.

override func viewWillAppear(animated: Bool) {

      super.viewWillAppear(animated)
      if self.updatedTitle != nil {
      self.navigationItem.title = self.updatedTitle//Create this String variable.
      }
}