navigationController 自定义backBarButtonItem事件

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

/**

  • 自定义系统默认back事件

  • 需要实现 -(UIViewController*)PopViewController;

  • return VC; //popToViewController:vc

  • return nil; //popViewControllerAnimated **/ -(UIViewController *)popViewControllerAnimated:(BOOL)animated{

    UIViewController *popVC = self.visibleViewController;

    if ([popVC respondsToSelector:@selector(PopViewController)]){ UIViewController *vc = [popVC performSelector:@selector(PopViewController) withObject:nil];

     if (vc && vc != self.viewControllers[self.viewControllers.count -2]) {
         [self popToViewController:vc animated:animated];
    
         NSMutableArray *items = [NSMutableArray array];
    
         for (UIViewController *vc in self.viewControllers) {
             [items addObject:vc.navigationItem];
         }
    
         [self.navigationBar setItems:items animated:YES];
    
         return vc;
     }
    

    } return [super popViewControllerAnimated:animated]; }

-(UIViewController*)PopViewController{ return 指定ViewCOntroller; }

转载于:https://my.oschina.net/u/868062/blog/417464

你可能感兴趣的:(navigationController 自定义backBarButtonItem事件)