iOS 获取当前视图viewController

网上搜索的大部分根本没法用,不知道为什么还那么多篇内容一样

//获取当前视图的控制器

- (UIViewController *)currentViewController {

for (UIView* next = [self superview]; next; next = next.superview) {

UIResponder *nextResponder = [next nextResponder];

if ([nextResponder isKindOfClass:[UIViewController class]]) {

return (UIViewController *)nextResponder;

}

}

return nil;

}

你可能感兴趣的:(iOS 获取当前视图viewController)