在 IOS 4.x 或更低版本中,将子视图添加到视图时不会调用 viewDidAppear 方法,为什么?

发布于 2024-12-15 01:42:46 字数 232 浏览 1 评论 0原文

在 iOS 4.x 或更低版本中,viewDidAppear 和 viewWillAppear、viewDidDisappear 和 viewWillDisappear 等 ViewController 的委托方法不会被调用。相同的方法在 iOS 5.x 上也可以正常工作。

为什么?这是 iOS 4.x 或更低版本中的错误吗?因为在 iOS 5.x 中,所有这些方法都会以正确的方式和顺序调用。

提前致谢, 姆鲁纳尔

In iOS 4.x or lower, viewDidAppear and viewWillAppear, viewDidDisappear and viewWillDisappear, such ViewController's delegate methods are not getting called. The same methods work fine with the iOS 5.x.

Why? Is it a bug in iOS 4.x or lower. Because in iOS 5.x all those methods gets called in proper manner and sequence.

Thanks in advance,
Mrunal

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

饭团 2024-12-22 01:42:46

对于 IOS4.xi 使用 UINavigationController 委托方法如下:

-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (SYSTEM_VERSION_LESS_THAN(@"5.0")) {
        [activeView viewDidAppear:YES];
    }
}
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (SYSTEM_VERSION_LESS_THAN(@"5.0")) {
        [activeView viewWillAppear:YES];
    }
}

我希望这有帮助!

For IOS4.x i use the UINavigationController delegate methods like this:

-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (SYSTEM_VERSION_LESS_THAN(@"5.0")) {
        [activeView viewDidAppear:YES];
    }
}
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (SYSTEM_VERSION_LESS_THAN(@"5.0")) {
        [activeView viewWillAppear:YES];
    }
}

I hope this helps!

半枫 2024-12-22 01:42:46

如果您的视图控制器是另一个视图控制器的子视图(即它是 UIViewController 内的 UINavigationController,反之亦然等),则子视图控制器的 viewDidAppear、viewWillAppear 等方法将不会被调用。解决方案是让家长像这样调用他们:

-(void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated];
    [child viewWillAppear:animated];
}

我知道 iOS 4.3 会发生这种情况。在 iOS 5 中,有一组新方法专门用于处理这些情况: 实现容器视图控制器

If your view controller is a child of another view controller, (i.e. it's a UINavigationController inside a UIViewController, or vice versa, etc.), the child's viewDidAppear, viewWillAppear, etc. methods will not get called. The solution is to have the parent call into them like:

-(void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated];
    [child viewWillAppear:animated];
}

I know this happens through iOS 4.3. In iOS 5 there is a new set of methods specifically for handling these cases: Implementing a Container View Controller

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文