HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iphone – viewWillDisappear和viewDidDisappear永远不会被调用大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_607_1@
我为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时,contentViewController永远不会收到viewWillDisappear,viewDidDisappear甚至viewDidUnload;

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

解决方法

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

大佬总结

以上是大佬教程为你收集整理的iphone – viewWillDisappear和viewDidDisappear永远不会被调用全部内容,希望文章能够帮你解决iphone – viewWillDisappear和viewDidDisappear永远不会被调用所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。