为什么viewDidAppear没有被触发? [英] why does viewDidAppear not get triggered?

查看:170
本文介绍了为什么viewDidAppear没有被触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个根视图控制器,在其viewDidLoad方法的索引0插入一个子视图。

i have a root view controller that inserts a subview at index 0 at its viewDidLoad method.

我试图让子视图成为firstResponder,在我的理解中,在子视图的viewDidAppear方法中。

i am trying to get the subview to become firstResponder, but can only do this - from my understanding - in the subview's viewDidAppear method.

这里是添加到根视图控制器的viewDidLoad方法的代码行:

here's the line of code i added to the root view controller's viewDidLoad method:

        [self.view insertSubview: subViewController.view atIndex: 0];

subviewcontroller有一个xib,subViewController.xib,它在运行时正确显示。然而,subViewController的viewDidAppear不会被触发。

the subviewcontroller has a xib, subViewController.xib, that is shown correctly at runtime. nevertheless, the subViewController's viewDidAppear does not get triggered.

任何想法为什么会发生这种情况?任何想法如何补救这 - 除了手动调用viewDidAppear(这样做导致失败成为firstResponder)?

any idea why this happens? any idea how to remedy this - apart from calling viewDidAppear manually (doing so results in failure to become firstResponder)?

感谢,

mbotta

推荐答案

您必须将视图以便它的delegate方法被调用。将视图控制器的视图添加到子视图数组将不会调用它们。首先,您应该阅读查看控制器编程指南从苹果,因为这将避免一些头痛,你正在创建通过这样做非标准的方式。

You have to push the view controller on to a navigation stack in order for it's delegate methods to get called. Adding your view controller's view to the subview array won't call them. The first thing you should do is read the View Controller Programming Guide from Apple as this will save you from some headaches you're creating by doing this in a non-standard way.

而不是将视图添加到您的根视图控制器子视图,请执行以下操作:

Instead of adding the view to your root view controller subviews, do this:

SubviewController *controller = [[SubviewController alloc] init];
[[self navigationController] pushViewController:controller animated:YES];
[controller release], controller = nil;

现在你的委托方法会被调用。如果你没有一个导航控制器作为你的根视图控制器,虽然,这将不工作。

Now your delegate methods will get called. If you don't have a navigation controller as your root view controller, though, this won't work.

这篇关于为什么viewDidAppear没有被触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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