我正在尝试在我的iPhone应用上创建一个后退按钮,我想回到我的着陆视图..我正在使用此代码,但它无法正常工作
UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
[back setFrame:CGRectMake(0, 0, 24, 24)];
[back setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
[back addTarget:self action:@selector(goback) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *btnBack = [[UIBarButtonItem alloc] initWithCustomView:back];
self.navigationItem.hidesBackButton= YES;
navEng.leftBarButtonItem = btnBack;
-(void)goback{ [self.navigationController popToRootViewControllerAnimated:YES]; }
答案 0 :(得分:0)
试试这个....刚改变了最后一行代码
UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom]; [back setFrame:CGRectMake(0, 0, 24, 24)]; [back setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
[back addTarget:self action:@selector(goback) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *btnBack = [[UIBarButtonItem alloc] initWithCustomView:back];
self.navigationItem.hidesBackButton= YES;
self.navigationItem.leftBarButtonItem = btnBack;
-(void)goback
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
答案 1 :(得分:0)
navEng 在标题文件中声明为IBoutlet
UINavigationItem
,并显示后退按钮并且操作处理正确但导航到上一个ViewController
没有工作
@property (nonatomic, strong) IBOutlet UINavigationItem *navEng;
UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
[back setFrame:CGRectMake(0, 0, 24, 24)];
[back setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
[back addTarget:self action:@selector(goback) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *btnBack = [[UIBarButtonItem alloc] initWithCustomView:back];
self.navigationItem.hidesBackButton= YES;
navEng.leftBarButtonItem = btnBack;
-(void)goback{
NSLog(@"back");
[self.navigationController popViewControllerAnimated:YES];
}