在一个demo中学到的, 以前没找到, 分享出来供大家学习
获取任意ViewController的navigationController
```
@implementation UIViewController (IMYPublic)
- (UINavigationController*)imy_navigationController
{
UINavigationController* nav = nil;
if ([self isKindOfClass:[UINavigationController class]]) {
nav = (id)self;
}
else {
if ([self isKindOfClass:[UITabBarController class]]) {
nav = [((UITabBarController*)self).selectedViewController imy_navigationController];
}
else {
nav = self.navigationController;
}
}
return nav;
}
@end
```