노블의 개발이야기

[iOS] UIView에서 상위 UIVewController 가져오기 본문

iOS

[iOS] UIView에서 상위 UIVewController 가져오기

더플러스 2015. 7. 13. 18:01

UIView에서 상위 UIVewController를 가져오기


@interface UIView (GetViewController)

- (UIViewController *)viewController;

@end


@implementation UIView (GetViewController)


- (UIViewController *)viewController;

{

id nextResponder = [self nextResponder];

if (nextResponder == nil) {

return nil;

}

NSLog(@"%s"object_getClassName(nextResponder));

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

return nextResponder;

else {

return [nextResponder viewController];

}

}


- (UIViewController*)getViewController {


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

        UIResponder* nextResponder = [next nextResponder];

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

            return (UIViewController*)nextResponder;

        }

    }

    return nil;


}



'iOS' 카테고리의 다른 글

[iOS] In App Purchase  (0) 2015.07.24
[iOS] Framework 만들기  (0) 2015.07.14
[iOS] UIActivityViewController  (0) 2015.07.13
[iOS] UIActionSheet  (0) 2015.07.13
[iOS] UIWebView 웹페이지 너비 맞추기  (0) 2015.05.14
Comments