开发者

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 开发者_JAVA百科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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜