Alexander_F
Alexander_F

Reputation: 2877

tabBarController and first Tab viewDidLoad

I have created a tabBarNavigated Application. In second tab, I do something that works fine, but now I want to do something in the first Tab, so first I try to NSLog a string, but I get no reaction.

- (void)viewDidLoad
{
 NSLog(@"Test");
}

If I add a label to the view, it will be displayed, but no reaction on my code.

if I start my app, i see this view, but i can't call any actions in this method, even if i change the tab, and go back to the first one, still no logs.

enter image description here

I try to NSlog in GehaltView

this is the mainWindow

enter image description here

viewWillAppear dosn't work :(

Upvotes: 0

Views: 2132

Answers (2)

Alexander_F
Alexander_F

Reputation: 2877

I found the solution, in interface builder i have to add a custom class to the forst tab.

Upvotes: 0

PengOne
PengOne

Reputation: 48398

The -viewDidLoad method is only called when your view is loaded. This method will not be called again unless the view gets unloaded, in which case -viewDidUnload will be called. A view can be unloaded if there is a memory issue, but otherwise they generally stick around.

If you want to trigger an action that happens every time the view appears, then you can use the -viewWillAppear: method instead. This method is called every time the view re-appears. You can track when the view disappears with -viewWillDisappear, and watch the two get called as you toggle between the two tabs.

Note also that -viewDidLoad may get called before the view appears, but -viewWillAppear will only be called when the view actually appears (or moments before, as the will indicates).

EDIT: The code should read

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    NSLog(@"View Will Appear");
}

EDIT: This entire answer assumes that you have a subclass of UIViewController. It seems to me that you are by-passing using viewControllers, which in general is a bad idea.

Upvotes: 3

Related Questions