dismissViewControllerAnimated到根视图

来源:互联网 发布:网络数字机顶盒 编辑:程序博客网 时间:2024/04/29 13:02

如果是在Controller中  则代码如下

-(void)backClick{        UIViewController *vc =  self;    while (vc.presentingViewController) {        vc = vc.presentingViewController;    }    [vc dismissViewControllerAnimated:YES completion:nil];    }

如果实在视图(View)中  则代码如下

-(void)backClick{        UIViewController *vc =  [self viewController];    while (vc.presentingViewController) {        vc = vc.presentingViewController;    }    [vc dismissViewControllerAnimated:YES completion:nil];            }/** 获取当前view的controller */- (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;}

该代码可返回到根(通过present过来的)Controller


该文章参考:http://blog.csdn.net/nunchakushuang/article/details/45198969

0 0
原创粉丝点击