網(wǎng)上搜索的大部分根本沒法用,不知道為什么還那么多篇內(nèi)容一樣
//獲取當(dāng)前視圖的控制器
- (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;
}