0

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.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Ilir V. Gruda
  • 1,562
  • 5
  • 17
  • 23
  • `UIViewController *vc = [navigationController.viewControllers objectAtIndex:index]; vc.title = @"title";` – Elliot Alderson May 21 '15 at 11:27
  • 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 May 21 '15 at 11:33
  • 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 May 21 '15 at 11:55

1 Answers1

1

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.
      }
}
Amit89
  • 3,000
  • 1
  • 19
  • 27
  • can you tell me what is `updatedTitle` is this a string variable or something else? Furthermore I already have a string variable that is updated by both ViewControler and Slide Out controller and I am replacing it with `updatedTitle`. but in both cases I am having an error 'ViewController' dose not have a member named ... – Ilir V. Gruda May 21 '15 at 12:32
  • This is a String variable in first view controller. – Amit89 May 21 '15 at 12:45
  • than I am having an error 'ViewController' dose not have a member named updatedTitle, even though I am creating it – Ilir V. Gruda May 21 '15 at 12:48
  • How you are accessing ViewController in your second class? – Amit89 May 21 '15 at 12:55
  • I am not sure what do you mean but accessing ViewController. But ViewController and the second class are not directly connected (they do not have segue between them). I have public variables that both of them can access and some functions from AppDelegate as well. Sorry for bothering you but I am quite new – Ilir V. Gruda May 21 '15 at 13:02
  • ViewController i meant first view controller. – Amit89 May 21 '15 at 13:35
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/78428/discussion-between-amit89-and-ilir-v-gruda). – Amit89 May 21 '15 at 13:48