在IOS6中的导航控制器上无法看到后退按钮

时间:2012-10-01 10:29:06

标签: iphone ios uinavigationbar ios6 uinavigationitem

我有一个由我以编程方式创建的自定义UINavigationcontroller。

问题在于,在IOS6中没有看到UINavigationBar默认的后退按钮,但是当我按下它时可以完成操作。

注意:在IOS5中可以看到后退按钮。

这是我用过的代码

- (void)customizeNavigationController:(UINavigationController *)navController
{
    UINavigationBar *navBar = [navController navigationBar];
    [navBar setTintColor:keyNavBarTintColor];

    UIImageView *myImageView = (UIImageView *)[navBar viewWithTag:keyNavBarBackgroundImageTag];
    if (myImageView == nil)
    {
      UIImage *img = [UIImage imageNamed:@"image.png"];
      CGRect rect = CGRectMake(0, 0, navBar.frame.size.width, navBar.frame.size.height);
      myImageView = [[UIImageView alloc] initWithFrame:rect];
      [myImageView setContentMode:UIViewContentModeScaleAspectFill];
      [myImageView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
      myImageView.image = img;
      [myImageView setTag:keyNavBarBackgroundImageTag];
      [navBar addSubview:myImageView];
      [myImageView release];
    }
    self.navImageView = myImageView;
}

1 个答案:

答案 0 :(得分:0)

试试这个:

UIImage *image = [UIImage imageNamed:kButtonBackInActive];

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:image forState:UIControlStateNormal];
[button addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(0, 0, 39.0f, 44.0f)];
button.contentEdgeInsets = (UIEdgeInsets){.left=-8};
button.showsTouchWhenHighlighted = NO;

UIBarButtonItem * backbutton = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];
[self.navigationItem setLeftBarButtonItem:backbutton];