ewWillDisappear和viewDidDisappear

ewWillDisappear和viewDidDisappear

本文介绍了viewWillDisappear和viewDidDisappear永远不会被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为PopoverController创建了自己的类(没有子类化UIPopoverController)以我想要的方式呈现ViewControllers。

I created my own class for PopoverController (Without subclassing UIPopoverController) to present ViewControllers in the way i want.

CustomPopoverController不是UIViewController,而是有一个ivar称为contentViewController,它是实际显示的VC。

CustomPopoverController is NOT a UIViewController, instead it has an ivar called "contentViewController" which is the VC that will actually be displayed.

当用户点击contentViewController以外的任何地方时,我实现了自己的dismissPopoverAnimated:以解除我的自定义弹出窗口frame:

I implemented my own "dismissPopoverAnimated:" to dismiss my custom popover when the user tap anywhere outside the contentViewController's frame:

-(void) dismissPopoverAnimated : (BOOL) animated
{
     // dismissalView is the view that intercept the taps outside.
    [self.dismissalView removeFromSuperview];
    self.dismissalView = nil;
    if (animated)
    {
        CGRect newFrame = self.view.frame;
        // When in landscape Mode the width of the screen is actually the "height"
        newFrame.origin.y = [UIScreen mainScreen].bounds.size.width;

        [UIView animateWithDuration:0.5
                         animations:^{self.view.frame = newFrame;}
         completion: ^(BOOL finished) {if(finished) [self.contentViewController.view removeFromSuperview];}];
    }
    else
    {
        [self.contentViewController.view removeFromSuperview];
    }
    isPresented = NO;
    [self.delegate customPopoverDidDismissPopover:self];
}

问题是,即使 removeFromSuperView - 动画与否, contentViewController 永远不会收到 viewWillDisappear viewDidDisappear 甚至 viewDidUnload 当我发布 contentViewController 时;

The problem is, that even though removeFromSuperView is called in any case - animated or not, the contentViewController never receives either viewWillDisappear, viewDidDisappear or even viewDidUnload when i'm releasing the contentViewController;

有谁知道为什么?
或者甚至更好地对viewWill ... / viewDid ...方法链以及它们应该被调用的时间点亮。

Does anyone have an idea why?Or even better throw some light on the chain of viewWill.../viewDid... method and when they supposed to be called.

推荐答案

当你通过UIView的方法添加子视图或删除子视图时,它永远不会导致拥有 UIViewController 调用 viewWillAppear viewDidAppear viewWillDisappear ,以及 viewDidDisapper 。只有那些由 UINavigationController 的方法管理的viewController,比如 pushViewController:animated: popViewControllerAnimated: ,或 presentModelViewController:aniamted: ...等等。他们将通知控制器视图的状态正在发生变化。

When you add subview or remove subview by the methods of UIView, it never cause owned UIViewController call viewWillAppear, viewDidAppear, viewWillDisappear, and viewDidDisapper. Only those viewController managed by the method of UINavigationController, like pushViewController:animated: or popViewControllerAnimated:, or presentModelViewController:aniamted: ... etc. They will notify about the status is changing for the view of controller.

这篇关于viewWillDisappear和viewDidDisappear永远不会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 05:14