开发者

Is it possible to reload a view when a tab bar item is pressed?

开发者 https://www.devze.com 2022-12-13 02:24 出处:网络
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开发

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消