切换选项卡栏选择后更新 UIViewControllers
我的选项卡中有两个视图控制器,它们都可以编辑数据。因此,每当用户在选项卡栏上进行切换时,我都需要调用 reload_data 函数。我怎样才能捕捉视图控制器的开关或外观。不知何故,在选项卡栏开关上不会调用 viewDidAppear。我不想为此使用 tabbarController 委托,因为几个 viewController 受到影响(并且我无法将它们全部设置为委托)。有什么好的方法可以解决这个问题呢?
例如这不起作用:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
[self reloadData];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
[self reloadData];
}
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?
e.g. this didn't work:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
[self reloadData];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
[self reloadData];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 Interface Builder,请确保定义了您希望重新加载的 viewController 的类(在 IB 中选择 ViewController,然后选择 CMD-4,确保将类定义为您希望调用 viewWillAppear 和 viewDidAppear 的类)在)。
如果您不使用 IB,请发布您的初始化/调用 viewController 的代码。
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).
If you're not using IB, post your code for init/calling the viewController.