返回导航控制器层次结构时如何触发 viewWillAppear?
当返回到 UINavigationController 的第一级时,我一直在尝试各种方法来触发一些代码,但是以下方法都不起作用...
// HomeViewController.m
-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
NSLog(@"trigger 1");
}
- (void)viewWillAppear:(BOOL)animated {
NSLog(@"trigger 2");
}
-(void) viewDidAppear:(BOOL)animated {
NSLog(@"trigger 3");
}
我开始认为我的应用程序设置错误了..是不是有什么问题UIViewControllers 中有 UIViewControllers 吗?
这是应用程序的笔尖。它是一个 UITabBarController,每个选项卡都有一个导航控制器,其中包含 UINavigationController 的第一页。此设置是方法未触发的原因吗?
这里未显示底部的 UIView,它链接到文件所有者的视图。更复杂的是,MainViewController 实际上是实用程序风格应用程序的另一面。
I've been trying various methods to trigger some code when returning to the first level of a UINavigationController, but none of the below work...
// HomeViewController.m
-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
NSLog(@"trigger 1");
}
- (void)viewWillAppear:(BOOL)animated {
NSLog(@"trigger 2");
}
-(void) viewDidAppear:(BOOL)animated {
NSLog(@"trigger 3");
}
I'm starting to think I've set up my app wrong.. is it something about having UIViewControllers within UIViewControllers?
This is the nib for the app.. it's a UITabBarController with a navigation controller for each tab, and within that the first page of the UINavigationController. Is this setup the reason why the methods are not triggering?
Not shown in this is a UIView at the bottom which is linked to the File Owner's view. And to make it more complicated, MainViewController is actually the flip side of a Utility-style app.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只是说我用另一种方式解决了这个问题。我需要调用像 viewWillAppear 这样的东西,因为当第二个视图中的某些内容发生更改时,我需要更新我的第一个视图表。
我实现它的方式是,在我的“tableView:commitEditingStyle”方法(在删除某些内容后调用)中,我将其放在最后。
reloadTheTable 是我的 HomeViewController 中的一个方法,它执行更新数组和 [tableView reloadData] 等操作;
这是很多括号。我确信我的笔尖可以设置得更简单。我认为卡斯帕罗夫说过他认为前面有四步……而四个括号是我的极限。
我通过做这样的事情来解决这个问题:
并慢慢添加它,直到找到我正在寻找的东西:
当您将视图放入视图中时,viewWillAppear 被取消的方式肯定有些奇怪。
Just to say I solved this another way. I needed to call something like viewWillAppear because I needed to update my first view table when something had changed in my second view.
The way I achieved it was, in my 'tableView: commitEditingStyle' method (called after I delete something), I put this at the end..
reloadTheTable is a method in my HomeViewController which does stuff like update arrays and [tableView reloadData] etc;
That's a lot of brackets. I'm sure my nib can be set up to make that simpler. I think Kasparov has said that he thinks four moves ahead... and four brackets is my limit.
I worked it out by doing things like this:
and slowly adding to it until I found what I was looking for:
There is something definitely odd in the way viewWillAppear gets cancelled when you puts views within views.