0

when viewController(A) go to the next viewController(B), I change the title's color, and it worked, but when I go back to the parent viewController(A), I change the title's color through viewWillAppear function, executed but didn't work, the color of title didn't change, How can I solve this problem? Thanks everyone.

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]}];
}

I find a solution: change title's color before go back to parent viewController(A) in willMoveToParentViewController:(UIViewController *)parent; function, Reference link,but the subclass viewController(B) is third party library , I can't use this function so that can't detect does it will work or not. Is there any other solution?

RateRebriduo
  • 265
  • 3
  • 11
  • Have you tried looking [here](https://stackoverflow.com/questions/7269035/voidviewwillappearboolanimated-doesnt-called)? May be of some help – tomerpacific Nov 27 '18 at 07:11
  • @tomerpacific viewWillAppear func executed but didn't work, when viewController C push to viewController A ,executed and worked, but when subclass viewControllerB go back to A, viewWillAppear executed but didn't work; – RateRebriduo Nov 27 '18 at 07:23
  • when you are saying executed but did not work, what do you mean? Are you debugging your program and you can see the viewWillAppear method being called and your logic being made? Have you seen that the object you are trying to change its title color, is defined? – tomerpacific Nov 27 '18 at 07:30
  • 1
    Well, I think the problem is that in the viewWillAppear function even though the code has been executed , but won't work. And I change to use viewDidAppear function, now it worked.@tomerpacific - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor redColor]}; } – RateRebriduo Nov 27 '18 at 07:37

1 Answers1

0

Try adding code to method - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; }

Sasha Tsvigun
  • 311
  • 5
  • 15