我有2个页面。 第一是的tableView和第二个是视图,当我点击任何单元格,进入下一个页面(view)的方式模态SEGUE。 我想在导航栏上的下一个页面中添加后退按钮。 这是我考虑到页面代码:ViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.lable.text = obji.Name;
self.lable2.text = obji.Descript;
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(Back)];
self.navigationItem.leftBarButtonItem = backButton;
}
- (IBAction)Back
{
//I dont know that how return pervious page
}
当您在您的评论说,您使用的是模态控制器
添加在viewWillAppear中以下
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:self action:@selector(Back)];
self.navigationItem.leftBarButtonItem = backButton;
而在
- (IBAction)Back
{
[self dismissViewControllerAnimated:YES completion:nil]; // ios 6
}
斯威夫特3
let backButton: UIBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(back))
self.navigationItem.leftBarButtonItem = backButton
func back() {
self.dismiss(animated: true, completion: nil) }
我有类似的问题,但我使用的斯威夫特。 以下是雨燕2.2的答案。
override func viewWillAppear(animated: Bool) {
let backButton: UIBarButtonItem = UIBarButtonItem(title: "Back", style: .Plain, target: self, action: #selector(back))
self.navigationItem.leftBarButtonItem = backButton;
super.viewWillAppear(animated);
}
func back() {
self.dismissViewControllerAnimated(true, completion: nil)
}