-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIViewController+EHMRCUMAnalytics.m
93 lines (81 loc) · 2.61 KB
/
UIViewController+EHMRCUMAnalytics.m
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// UIViewController+EHMRCUMAnalytics.m
// ieltsListen
//
// Created by 王志平 on 2017/2/23.
// Copyright © 2017年 enhance. All rights reserved.
//
#import "UIViewController+EHMRCUMAnalytics.h"
@implementation UIViewController (EHMRCUMAnalytics)
- (void)addControllersTo:(id)controller
{
Class toClass = nil;
if ([controller isKindOfClass:[NSString class]]) {
toClass = NSClassFromString(controller);
} else {
toClass = [controller class];
}
NSMutableArray *temp = [NSMutableArray array];
[self.navigationController.viewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (obj != self) {
[temp addObject:obj];
}
*stop = [obj isKindOfClass:toClass];
}];
[temp addObject:self];
self.navigationController.viewControllers = temp;
}
- (void)addControllersuntil:(id)controller
{
Class toClass = nil;
if ([controller isKindOfClass:[NSString class]]) {
toClass = NSClassFromString(controller);
} else {
toClass = [controller class];
}
NSMutableArray *temp = [NSMutableArray array];
[self.navigationController.viewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
BOOL same = [obj isKindOfClass:toClass];
if (obj != self && !same)
{
[temp addObject:obj];
}
*stop = same;
}];
[temp addObject:self];
self.navigationController.viewControllers = temp;
}
- (void)deleteControllerFrom:(id)controller
{
Class fromClass = nil;
if ([controller isKindOfClass:[NSString class]]) {
fromClass = NSClassFromString(controller);
} else {
fromClass = [controller class];
}
__block BOOL have = NO;
[self.navigationController.viewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:fromClass])
{
have = YES;
*stop = YES;
}
}];
if (have)
{
[self.navigationController.viewControllers enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (![obj isKindOfClass:fromClass])
{
if (obj != self)
{
[obj removeFromParentViewController];
}
}
else
{
*stop = YES;
}
}];
}
}
@end