试试这个代码
UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *backBtnImage = [UIImage imageNamed:@"BackBtn.png"] ;
[backBtn setBackgroundImage:backBtnImage forState:UIControlStateNormal];
[backBtn addTarget:self action:@selector(goback) forControlEvents:UIControlEventTouchUpInside];
backBtn.frame = CGRectMake(0, 0, 54, 30);
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:backBtn] ;
self.navigationItem.leftBarButtonItem = backButton;
然后像这样定义 goback 方法
- (void)goback
{
[self.navigationController popViewControllerAnimated:YES];
}
注意:BackBtn.png 将包含 ToDo 文本和后退按钮图像...
另一种方式
如果您想不使用图像,请添加以下代码...
-(void)viewWillAppear {
self.title = @"Your Title"
}
-(void)viewWillDissapear {
self.title = @"ToDo"
}
当您转到下一个视图时,这将创建 ToDo...