如果是在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.youkuaiyun.com/nunchakushuang/article/details/45198969