美文网首页iOS Developer
一行代码解决NavigationController多次push

一行代码解决NavigationController多次push

作者: 蜂子阁先生 | 来源:发表于2017-03-21 10:54 被阅读493次

新建文件如下

UINavigationController+PushSafe.h


//
//  UINavigationController+PushSafe.h
//  Medical
//
//  Created by chenguibang on 2017/3/21.
//  Copyright © 2017年 chenguibang. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UINavigationController(PushSafe)
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated safe:(BOOL)safe;
@end


UINavigationController+PushSafe.h


//
//  UINavigationController+PushSafe.m
//  Medical
//
//  Created by chenguibang on 2017/3/21.
//  Copyright © 2017年 chenguibang. All rights reserved.
//

#import "UINavigationController+PushSafe.h"

@implementation UINavigationController(PushSafe)


-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated safe:(BOOL)safe{
    if ([[self.viewControllers lastObject] isKindOfClass:viewController.class]&&safe) {
        return ;
    }
    [self pushViewController:viewController animated:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

使用方法


[self.navigationController pushViewController:chatController animated:YES safe:YES];

相关文章

网友评论

    本文标题:一行代码解决NavigationController多次push

    本文链接:https://www.haomeiwen.com/subject/kpwwnttx.html