zoukankan      html  css  js  c++  java
  • 解决:IOS viewDidAppear/viewWillAppear无法被调用

    本文转载至 http://my.oschina.net/lvlove/blog/82264

     

    原因:

    苹果的文档是这样描述的:

    If the view belonging to a view controlleris added to a view hierarchy directly, the view controller will not receivethis message. If you insert or add a view to the view hierarchy, and it has aview controller, you should send the associated view controller this messagedirectly. Failing to send the view controller this message will prevent anyassociated animation from being displayed.

        实际情况中,在addSubview, presentModelviewController或者TabViewController中加载viewController时,viewDidAppear/viewWillAppear都是无法被调用的。(iphone)

    解决:

         如果是pushViewController的情况,可以直接利用UINavigationControllerDelegate,这样:

    .h文件中:

    <UINavigationControllerDelegate>

    .m文件中:

       self.navigationController.delegate =self

    -(void)navigationController:(UINavigationControlle*)

        navigationController willShowViewController:

        (UIViewController *)viewController animated:(BOOL)animated  

    {    

        [viewController viewWillAppear:animated];

    }

    -(void)navigationController:(UINavigationControlle*) 

        navigationController didShowViewController:

        (UIViewController *)viewController animated:(BOOL)animated

    {

        [viewController viewDidAppear:animated];

    }

  • 相关阅读:
    tomcat8.5.57源码阅读笔记2
    tomcat8.5.57源码阅读笔记1
    KVM openstack
    爬虫进阶版
    react 之setChild子组件传值父组件
    Linux找死锁、cpu100%
    Java定时任务
    Java工具类HttpUtil
    Java后台远程下载url文件并远程上传文件
    jQuery上传文件
  • 原文地址:https://www.cnblogs.com/Camier-myNiuer/p/3878113.html
Copyright © 2011-2022 走看看