您可以使用此代码,在您的 viewWillAppear 中调用此函数,
- (void)AddBackButtonForiPhone {
self.navigationItem.hidesBackButton = YES;
[backButtonView removeFromSuperview]; // It is UIView
if (backButtonView) {
[backButtonView release];
backButtonView = nil;
}
if (gblAppDelegate.portrait) {
backButtonView = [[UIView alloc] initWithFrame:CGRectMake(10,6,80,30)];
}else{
backButtonView = [[UIView alloc] initWithFrame:CGRectMake(10,0,80,30)];
}
NSString *strText = @"Back";//self.strPreviousTitle;
UIButton *btnBack = [[UIButton alloc] initWithFrame:CGRectMake(2, 0, 80, 27)];
[btnBack setTitle:strText forState:UIControlStateNormal];
[btnBack setTitleEdgeInsets:UIEdgeInsetsMake(0, -16, 0, 0)];
[btnBack setImageEdgeInsets:UIEdgeInsetsMake(0, -16, 0, 0)];
[btnBack setImage:[UIImage imageNamed:@"left_arrow"] forState:UIControlStateNormal];
btnBack.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:17];
[btnBack addTarget:self action:@selector(btnBack:) forControlEvents:UIControlEventTouchUpInside];
[backButtonView addSubview:btnBack];
[btnBack release];
[self.navigationController.navigationBar addSubview:backButtonView];
}
并在 viewWillDisappear 中使用此代码。
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[backButtonView removeFromSuperview];
//[gblAppDelegate ShowMainMenu];
}
- (void)btnBack:(UIButton *)sender {
// write your pop logic here
}