首页 > 代码库 > ios 获取当前view的controller

ios 获取当前view的controller

 //获取viewcontroller

 - (UIViewController *)viewController {

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

        UIResponder *nextResponder = [next nextResponder];

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

             

                return (UIViewController *)nextResponder;

            }

        }

         return nil;

 }