viewWillDisappear和viewDidDisappear永远不会被调用

时间:2011-05-05 08:12:24

标签: iphone objective-c ios ipad uiviewcontroller

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

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

当用户点击contentViewController框架之外的任何地方时,我实现了自己的“dismissPopoverAnimated:”以关闭我的自定义弹出窗口:

-(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也永远不会收到viewWillDisappearviewDidDisappear甚至{{1}当我发布viewDidUnload时;

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

1 个答案:

答案 0 :(得分:10)

当你通过UIView的方法添加子视图或删除子视图时,它永远不会导致拥有UIViewController个人viewWillAppearviewDidAppearviewWillDisappearviewDidDisapper 。只有那些由UINavigationController方法管理的viewController,如pushViewController:animated:popViewControllerAnimated:,或presentModelViewController:aniamted: ...等等。他们会通知有关状态正在变化的视图控制器。