zoukankan      html  css  js  c++  java
  • iPhone开发 让viewDidAppear/viewWillAppear 在页面加载前始终调用

    viewDidAppear/viewWillAppear in UINavigationController not be called

    When you push or pop a view controller on/off a navigaction controller's stack, the usual viewWillAppear / viewDidappear methods aren't called. If you want to ensure they're always called, just add the UINavigationControllerDelegate protocol to your root view controller:

    @interface RootViewController : UIViewController <UINavigationControllerDelegate> {
    UINavigationController *navController;
    }

    Then implement these two methods:

    - (void)navigationController:(UINavigationController *)navigationController 
    willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
    {
    [viewController viewWillAppear:animated];
    }

    - (void)navigationController:(UINavigationController *)navigationController
    didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
    {
    [viewController viewDidAppear:animated];
    }

    Be sure to set the root view controller as the delegate for the nav controller. Now viewWillAppear / viewDidAappear will be called whenever a controller is pushed/popped from the stack.

    If you want to call the viewWillDisappear/viewDidDisappear methods, your view controller still has to do that manually before popping itself off the nav stack.

  • 相关阅读:
    TCP/IP研究(1)-Timer(2)
    linux学习
    TCP/IP研究(2)-TCB
    vi学习笔记
    TCP/IP研究(1)-Timer
    yxr:Makefile 简单样本
    zt:vim环境配置
    zt:文件轻松比对,伟大而自由的比较软件们
    就是这么简单!使用Rest-assured 测试Restful Web Services
    手把手教你接口自动化测试 – SoapUI & Groovy
  • 原文地址:https://www.cnblogs.com/cplusplus/p/2245920.html
Copyright © 2011-2022 走看看