在.h文件中声明一个方法
- (UIViewController *)VC;
在.m文件中实现
//获取view中的导航栏 通过响应者链来 查找
- (UIViewController *)VC {
for (UIView *next = [self superview]; next; next = next.superview) {
UIResponder *nextResponder = [next nextResponder];
if ([nextResponder isKindOfClass:[UINavigationController class]]) {
return (UINavigationController *)nextResponder;
}
}
return nil;
}