How can I go back to the previous view from root view?
- (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]];
You can pop the view.
[self.navigationController popViewControllerAnimated:YES];
You can dismiss it as well.
dismissModalViewcontrollerAnimated
EDIT: If you are adding the view then you need to remove your view.
[self.view removeFromSuperView];
If you used a navigationController to push the view you can make use of popViewController: animated:
method. If you presented the view as a modal view you can make use of dismissModalViewcontrollerAnimated:
method
It seems you are not pushing or presenting the aNavigationController
. You are just adding it as a subview
. Neither popViewControlle
r nor dismissModalViewController
won't work here. You have to just remove it from its superView. Try this.
- (void)cancel {
[self.view removeFromSuperView];
}
Add This.
[self.view removeFromSuperview]
精彩评论