viewDidAppear没有被调用 [英] viewDidAppear not getting called

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

问题描述

在我的主UIViewController中,我将主屏幕视图控制器添加为子视图:

In my main UIViewController I am adding a homescreen view controller as subview's:

   UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:vc];
        controller.navigationBarHidden = YES;
        controller.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
        [self addChildViewController:controller];
        [self.view insertSubview:controller.view atIndex:0];
        [controller didMoveToParentViewController:self];    

问题是viewDidAppear和viewWillAppear只调用一次,就像viewDidLoad一样。为什么是这样?如何让它工作?

The issue is that viewDidAppear and viewWillAppear is only called once, just like viewDidLoad. Why is this? How do I make this to work?

基本上在vc中我没有得到viewDidAppear或viewWillAppear。

Basically inside vc I am not getting viewDidAppear nor viewWillAppear.

I也只是尝试在没有导航控制器的情况下添加UIViewController但它仍然不起作用:

I also just tried adding the UIViewController without the navigation controller and it still doesn't work:

vc.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
        [self addChildViewController:vc];
        [self.view insertSubview:vc.view atIndex:0];
        [vc didMoveToParentViewController:self];    


推荐答案

使用presentModalViewController或segues或pushViewController呈现视图控制器应修复它。

Presenting view controllers using presentModalViewController or segues or pushViewController should fix it.

或者,如果由于某种原因你想要在没有内置方法的情况下显示你的视图,在你自己的代码中你应该手动调用这些方法。这样的事情:

Alternatively, if for some reason you want to present your views without the built-in methods, in your own code you should be calling these methods manually. Something like this:

[self addChildViewController:controller];
BOOL animated = NO;
[controller viewWillAppear:animated];
[self.view insertSubview:controller.view atIndex:0];
[controller viewDidAppear:animated];
[controller didMoveToParentViewController:self];   

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

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