问题描述
我在一个标签栏中有两个视图控制器,它们都可以编辑数据.因此,每当用户在选项卡栏上进行切换时,我都需要调用reload_data函数.如何捕捉开关或视图控制器的外观.标签栏开关上不以某种方式调用viewDidAppear.而且我不想为此使用tabbarController委托,因为几个viewController会受到影响(而且我无法将它们全部设置为委托).解决这个问题的好方法是什么?
I have two view controllers in a tabbar which can both edit data. Therefore, I need to call a reload_data function whenever the user makes a switch on the tabbar. How can I catch the switch or the appearance of the viewcontroller. Somehow viewDidAppear is not called on a tabbar switch. And I do not want to use the tabbarController delegate for this, because several viewControllers are affected (and I cannot set them all as delegate). What is a good way to solve this?
例如这不起作用:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
[self reloadData];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
[self reloadData];
}
推荐答案
如果您使用的是Interface Builder,请确保定义了希望重新加载的viewController的类(在IB中选择ViewController,然后选择CMD-4,确保将类定义为您要调用viewWillAppear和viewDidAppear的类.
If you're using Interface Builder, make sure the class for the viewController your expecting to reload is defined (Select the ViewController in IB, then CMD-4, make sure class is defined to be the class you want viewWillAppear and viewDidAppear to be called in).
如果您不使用IB,请发布用于初始化/调用viewController的代码.
If you're not using IB, post your code for init/calling the viewController.
这篇关于切换选项卡选择后更新UIViewControllers的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!