UINavigationController 重写导航栏的返回事件

遇到需要重写导航返回事件,因为是用的系统的NavigationController ,查了下网上的资料,需要重写什么的,挺麻烦的,看到有人说自己写个通明的button,就试了下。

btn_back = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_TOP, JX_SCREEN_TOP)];

    [btn_back addTarget:self action:@selector(onBack) forControlEvents:UIControlEventTouchUpInside];

    [self.navigationController.navigationBar addSubview:btn_back];


- (void)onBack

{

//不移除的话跳转之后导航栏的返回键就被挡住不管用了,也不报错

    [btn_back removeFromSuperview];

    for (UIViewController *vc in self.navigationController.viewControllers) {

        if ([vc isKindOfClass:[NTESMyWalletVC class]]) {

            [self.navigationController popToViewController:vc animated:YES];

        }

    }

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容