zoukankan      html  css  js  c++  java
  • iOS 导航栏返回按钮时间action获取

    UIViewController+BackButtonHandler.h

    #import <UIKit/UIKit.h>

    @protocol BackButtonHandlerProtocol <NSObject>

    @optional

    // Override this method in UIViewController derived class to handle 'Back' button click

    -(BOOL)navigationShouldPopOnBackButton;

    @end

    @interface UIViewController (BackButtonHandler) <BackButtonHandlerProtocol>

    @end

    UIViewController+BackButtonHandler.m

    #import "UIViewController+BackButtonHandler.h"

    @implementation UIViewController (BackButtonHandler)

    @end

    @implementation UINavigationController (ShouldPopOnBackButton)

    - (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item {

    if([self.viewControllers count] < [navigationBar.items count]) {

    return YES;

    }

    BOOL shouldPop = YES;

    UIViewController* vc = [self topViewController];

    if([vc respondsToSelector:@selector(navigationShouldPopOnBackButton)]) {

    shouldPop = [vc navigationShouldPopOnBackButton];

    }

    if(shouldPop) {

    dispatch_async(dispatch_get_main_queue(), ^{

    [self popViewControllerAnimated:YES];

    });

    } else {

    // Workaround for iOS7.1. Thanks to @boliva - http://stackoverflow.com/posts/comments/34452906

    for(UIView *subview in [navigationBar subviews]) {

    if(subview.alpha < 1.) {

    [UIView animateWithDuration:.25 animations:^{

    subview.alpha = 1.;

    }];

    }

    }

    }

    return NO;

    }

    方法提

    x x x.m

    -(BOOL) navigationShouldPopOnBackButton ///在这个方法里写返回按钮的事件处理

    {

        [self.navigationController popViewControllerAnimated:YES];

        

        return YES;

        

    }

    @end

  • 相关阅读:
    51nod 1051【基础】
    HDU5971【瞎搞】
    Lightoj1018 【状压DP】
    HDU2604【矩阵快速幂】
    HDU1501【简单DP】
    HDU3555【数位DP】
    Lightoj1037【状压DP】
    51nod 1099【贪心】
    HDU5950【矩阵快速幂】
    51nod 1049【经典】
  • 原文地址:https://www.cnblogs.com/aiwoqu/p/4708590.html
Copyright © 2011-2022 走看看