//
//  UIView+FindUIViewController.m
//  raynokorea
//
//  Created by Dev.swing on 2016. 2. 19..
//  Copyright © 2016년 RaynoKorea. All rights reserved.
//

#import "UIView+FindUIViewController.h"

@implementation UIView (FindUIViewController)

- (UIViewController *) firstAvailableUIViewController {
    // convenience function for casting and to "mask" the recursive function
    return (UIViewController *)[self traverseResponderChainForUIViewController];
}


- (id) traverseResponderChainForUIViewController {
    id nextResponder = [self nextResponder];
    
    NSLog(@"next responder : %@", nextResponder) ;
    
    if ([nextResponder isKindOfClass:[UIViewController class]]) {
        
        return nextResponder;
    } else if ([nextResponder isKindOfClass:[UIView class]]) {
        
        return [nextResponder traverseResponderChainForUIViewController];
    } else {
        
        return nil;
    }
}

@end