English 中文(简体)
why does viewDidAppear not get triggered?
原标题:

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

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

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

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

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

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

thanks,

mbotta

最佳回答

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.

问题回答

If I recall correctly (sorry can t find the place in docs now) -viewDidAppear does not get called for subviews. You must call it manually in the -viewDidAppear method of parent view controller.





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签