Is it possible to reload a view when a tab bar item is pressed?
It doesn't seem like each time a view is presented via the tab bar, that the viewDidAppear
method gets called. I've searched as much as I could on this issue, but haven't really found a definiti开发者_高级运维ve answer.
Are there any suggestions or workarounds to this?
In order for viewWillAppear
and viewDidAppear
to function properly in a tab bar controller, you'll want to be sure to call those methods when you display the tab bar controller itself. That is, if you are creating your UITabBarController
programmatically, be sure to call those methods:
UITabBarController *myTabBarController = [[UITabBarController alloc] init];
[myTabBarController setViewControllers:myViewControllerArray];
[myTabBarController viewWillAppear:NO];
[[self view] addSubview:[myTabBarController view]];
[myTabBarController viewDidAppear:NO];
If your tab bar controller is being created in a NIB file, this doesn't apply - and in that case I'm not sure why your viewDidAppear
method would not be called automatically.
I personally use the viewWillAppear:(BOOL)animated
method.
精彩评论