viewWillAppear in viewcontrollers of a tabbar
Asked Answered
M

4

10

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

Maryalice answered 17/7, 2010 at 15:44 Comment(1)
I'm not sure it is same problem... but might worth to loot #131562Dissever
I
-1

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

Use setNeedsDisplay on the viewController's view instead.

Interlunar answered 17/7, 2010 at 15:52 Comment(3)
Where would I call setNeedsDisplay from? The problem is that I need a hook for when the user chooses a new viewcontroller from the tabbarMaryalice
Oh, sory, I mixed up things here a little bit. I'm not sure why the viewWillAppear is not getting called, but I know a way around it: Make some object a tabBarController delegate, and it will the send the message, that a new view was selected, and call view will appear from there.Interlunar
Sounds like an interesting idea, I'll give that a try tomorrow :-)Maryalice
A
10

You may use the tabbar controller delegate works like a charm

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

}
Agonistic answered 13/6, 2012 at 11:11 Comment(0)
T
1

Please see my answer here

iPhone viewWillAppear not firing

Tresa answered 26/7, 2011 at 17:8 Comment(0)
G
1

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() {

}
Graphology answered 28/5, 2017 at 2:49 Comment(0)
I
-1

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

Use setNeedsDisplay on the viewController's view instead.

Interlunar answered 17/7, 2010 at 15:52 Comment(3)
Where would I call setNeedsDisplay from? The problem is that I need a hook for when the user chooses a new viewcontroller from the tabbarMaryalice
Oh, sory, I mixed up things here a little bit. I'm not sure why the viewWillAppear is not getting called, but I know a way around it: Make some object a tabBarController delegate, and it will the send the message, that a new view was selected, and call view will appear from there.Interlunar
Sounds like an interesting idea, I'll give that a try tomorrow :-)Maryalice

© 2022 - 2024 — McMap. All rights reserved.