zoukankan      html  css  js  c++  java
  • 有关UIViewController函数调用与否的测试

    问题:当UIViewController的view通过add的方式添加到其他controller上时,导致viewWillAppear等这些函数不被调用

    solve:当ios的版本从5.0开始之后,UIViewController的view不管是通过何种方式增加到其他的controller上,viewWillAppear、viewDidAppear等这些函数都会执行,只有5.0以下的版本才需要做特殊处理


    特殊处理如下:
         只需要在UINavigationController的根controller中实现就行

    .h文件,实现UINavigationControllerDelegate
    @interface DPayGameShopViewController : UIViewController<UINavigationControllerDelegate>

    .m文件:
    - (void)viewDidLoad {
        [super viewDidLoad];
         //判断系统版本
        if ([[DPayConfig sharedInstance] isLowIOSVersion] && nil == self.navigationController.delegate) {
            self.navigationController.delegate = self;
        }
    }

    - (void)dealloc {
        self.navigationController.delegate = nil;
        [super dealloc];
    }

    #pragma mark - UINavigationControllerDelegate method

    - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
         //此处还可以调用viewController其他的类方法  如viewDidAppear等
        [viewController viewWillAppear:animated];
    }

    然后对应每个页面只要实现viewWillAppear这些方法即可
  • 相关阅读:
    3.3测试复盘
    计算机网络-运输层面试题整理
    3.2专项测试复盘
    2.27专项测试复盘
    2.26排序专项测试复盘
    2.25专项测试复盘
    前端基础笔记1
    2.24专项测试复盘
    2.23专项测试复盘
    更新pip报错AttributeError: 'NoneType' object has no attribute 'bytes'
  • 原文地址:https://www.cnblogs.com/cnsec/p/11515851.html
Copyright © 2011-2022 走看看