UINavigationController和viewWillDisappear [英] UINavigationController and viewWillDisappear

查看:114
本文介绍了UINavigationController和viewWillDisappear的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的应用程序中有一个UINavController,并且在用户按下后退按钮时尝试执行方法。我到处搜索,只能找到一些在上下文中没有意义的点点滴滴。

So I have a UINavController in my app and am trying to execute a method when the user presses the back button. I have searched everywhere and can only find bits and pieces that don't really make sense out of context.

当用户按下后退按钮关闭当前视图时,有没有办法实现某种检查? (弹出视图的viewWillDisappear方法由于某种原因永远不会被调用。我确实读过它除非你转发那个调用吗?)听起来是否正确,是否有人有任何想法或建议?在此先感谢。

Is there a way to implement some sort of check that catches when the user presses the back button to dismiss the current view? (the viewWillDisappear method for the view being popped never gets called for some reason. I did read that it doesn't unless you forward that call?) Does that sound right, and does anyone have any ideas or suggestions? Thanks in advance.

推荐答案

AFAIK,如果您通过代码将UINavigationController添加到UIView,它将不会将这些消息发送到这是默认的子视图。只有当UINavigationController本身接收到这些调用时才会执行此操作。也许这是你的问题(我不知道你的视图设置)。

AFAIK, if you add a UINavigationController to a UIView via code, it won't send those messages to it's subviews by default. It will only do this if the UINavigationController received these calls itself. Maybe this is your problem (I don't know your view setup).

因此,在添加UINavigationController的视图时,请务必手动将这些消息发送给它。

So, when adding the view of the UINavigationController, be sure to manually send it these messages.

UINavigationController *navigationController = [UINavigationController alloc] initWithRootViewController:rootViewController];

[navigationController viewWillAppear:NO];
[aView addSubview:navigationController.view];
[navigationController viewDidAppear:NO];

至少,这是我在开发过程中发现的。一直在寻找这个,我仍然不明白其背后的理由。

At least, this is what I found during development. Been searching for this for a long time and I still don't understand the rationale behind it.

这篇关于UINavigationController和viewWillDisappear的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆