美文网首页
iOS 获取View所在控制器UIViewController

iOS 获取View所在控制器UIViewController

作者: T_label | 来源:发表于2016-08-12 11:49 被阅读67次
  • 方法
    -(UIViewController *)viewController
    {
    for (UIView *next = [self superview]; next; next = next.superview) {
    UIResponder *nextResponser = [next nextResponder];
    if ([nextResponser isKindOfClass:[UIViewController class]]) {
    return (UIViewController *)nextResponser;
    }
    }
    return nil;
    }

  • 调用
    SecondViewController *Second = [[SecondViewController alloc] init];
    UIViewController *controller = [self viewController];//调用
    [controller.navigationController pushViewController: Second animated:YES];

相关文章

网友评论

      本文标题:iOS 获取View所在控制器UIViewController

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