如何从根视图返回上一个视图? [英] How can I go back to the previous view from root view?

查看:56
本文介绍了如何从根视图返回上一个视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

- (void)cancel {
// What should I do here?
}

// root view controller
- (void)viewDidLoad {
    [super viewDidLoad];

    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel)];
    self.navigationItem.leftBarButtonItem = cancelButton;
    [cancelButton release];     
}

我在导航栏中添加了取消按钮.按下取消按钮后,我想从根视图返回上一个视图.取消该怎么办?我这样添加了根视图控制器.

I added cancel button in the navigation bar. I want to go back to the previous view from root view when cancel button is pressed. What do I have to do in cancel? I added root view controller like this.

RootController *rootController = [[RootController alloc]initWithStyle:UITableViewStylePlain];               
UINavigationController *aNavigationController = [[UINavigationController alloc]initWithRootViewController:rootController];
self.naviController = aNavigationController;
[aNavigationController release];
[rootController release];
[self.view addSubview:[naviController view]];

推荐答案

您可以弹出视图.

[self.navigationController popViewControllerAnimated:YES];

您也可以将其关闭.

dismissModalViewcontrollerAnimated

如果要添加视图,则需要删除视图.

If you are adding the view then you need to remove your view.

[self.view removeFromSuperView];

这篇关于如何从根视图返回上一个视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆