JLChen
2021-05-18 a869383e163a18cdedcf587383c1eca043129754
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//
//  Copyright © 2020 dahua. All rights reserved.
//
 
#import "UINavigationController+Pop.h"
 
 
@implementation UINavigationController (Pop)
 
 
- (void)lc_popToViewController:(NSString *)vc Filter:(NSInteger (^)(NSArray * _Nonnull vcs))filter animated:(BOOL)animated {
    dispatch_async(dispatch_get_main_queue(), ^{
        NSMutableArray *VCArray = [NSMutableArray array];
           for (NSInteger a = self.viewControllers.count-1; a>=0; a--) {
               UIViewController *subVC = self.viewControllers[a];
               if ([subVC isKindOfClass:NSClassFromString(vc)]) {
                   [VCArray addObject:subVC];
               }
           }
        if (VCArray.count == 0) {
            NSLog(@"没有找到指定的VC");
            return ;
        }
        NSInteger index = 0;
        if (filter) {
           index = filter(VCArray);
        }
           
        UIViewController * confirmVC = (UIViewController*)VCArray[index];
        [self popToViewController:confirmVC animated:animated];
    });
}
 
@end