niklassaers
niklassaers

Reputation: 8810

viewWillAppear in viewcontrollers of a tabbar

In my tab-bar I have four viewcontrollers, and what happens in one can affect the view of the other, so I may need to reload some elements in the viewcontroller when it becomes visible. Normally I'd fix that by implementing viewWillAppear, but when I switch between the tabs, viewWillAppear does not seem to get called. How can I fix that, or what should I do instead?

Update: as a PS I should add that this is a tabbarcontroller in a navigationcontroller hierarchy

Cheers

Nik

Upvotes: 10

Views: 7650

Answers (4)

Brian Ogden
Brian Ogden

Reputation: 19212

And in case you find this question because you would like to update something in the UITabBarController itself, not the UIViewControllers of a UITabBarController, like the OP's question. For example, hiding or displaying a custom UITabBarButton. In Swift 3.0 overriding setNeedsStatusBarAppearanceUpdate of my UITabBarController class worked for me.

override func setNeedsStatusBarAppearanceUpdate() {

}

Upvotes: 1

tadejsv
tadejsv

Reputation: 2092

viewWillAppear should only be used when the view appears, and not for updating it.

Use setNeedsDisplay on the viewController's view instead.

Upvotes: -1

Radix
Radix

Reputation: 3657

You may use the tabbar controller delegate works like a charm

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    [viewController viewWillAppear:YES];

}

Upvotes: 10

Sam
Sam

Reputation: 3659

Please see my answer here

iPhone viewWillAppear not firing

Upvotes: 1

Related Questions