美文网首页
iOS通过UIView获取当前所在的UIViewControll

iOS通过UIView获取当前所在的UIViewControll

作者: jazzfly | 来源:发表于2019-10-08 15:00 被阅读0次

可以将该方法写到基类或者写到UIView分类当中

- (UIViewController *)getCurrentViewController {
    UIResponder *next = self.nextResponder;
    
    do {
        
        //判断响应者是否为视图控制器
        if ([next isKindOfClass:[UIViewController class]]) {
            return (UIViewController *)next;
        }
        
        next = next.nextResponder;
        
    } while (next != nil);
    
    return nil;
}

相关文章

网友评论

      本文标题:iOS通过UIView获取当前所在的UIViewControll

      本文链接:https://www.haomeiwen.com/subject/syeiyctx.html