-
Notifications
You must be signed in to change notification settings - Fork 0
/
UINavigationController+UUCustomRoot.m
38 lines (32 loc) · 1.12 KB
/
UINavigationController+UUCustomRoot.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
//
// UINavigationController+UUCustomRoot.m
// UUCustomRoot
//
// Created by Ye Yang on 16/5/18.
// Copyright © 2016年 iceyouyou. All rights reserved.
//
#import "UINavigationController+UUCustomRoot.h"
//#pragma GCC diagnostic ignored "-Wundeclared-selector"
@implementation UINavigationController (UUCustomRoot)
- (void)popToCustomRootViewControllerAnimated:(BOOL)animated {
UIViewController *customRootVC = nil;
NSUInteger index = [[self viewControllers] indexOfObject:[self topViewController]];
for (int i = (int)index - 1; i > 0; i--) {
UIViewController *preVC = [self.viewControllers objectAtIndex:i];
SEL sel = @selector(isCustomRootViewController);
if ([preVC respondsToSelector:sel]) {
IMP imp = [preVC methodForSelector:sel];
BOOL (*func)(id, SEL) = (void *)imp;
if (func(preVC, sel)) {
customRootVC = preVC;
break;
}
}
}
if (customRootVC) {
[self popToViewController:customRootVC animated:animated];
} else {
[self popToRootViewControllerAnimated:animated];
}
}
@end