iPhone - 导航栏后退按钮项目没有响应

时间:2011-03-19 15:02:50

标签: iphone uinavigationitem

我有一个像这样的全屏modalView:

PreferencesController *nextWindow = [[[PreferencesController alloc] initWithNibName:@"Preferences" bundle:nil] autorelease];
UINavigationController* navController = [[[UINavigationController alloc] initWithRootViewController:nextWindow] autorelease];
[self presentModalViewController:navController animated:YES];

然后从这个modalView我推出另一个视图:

    MyController *nextWindow = [[[MyController alloc] initWithNibName:@"tmp" bundle:nil] autorelease];
    [self.navigationController pushViewController:nextWindow animated:YES];

在这个新控制器中,我有这个viewDidLoad:

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"Borders";
    self.navigationController.navigationBarHidden = NO;
}

leftBarButtonItem未激活,我的意思是触摸它不会突出显示它,也不会返回到上一个视图。

我的视图显示为fullScreen,在应用程序初始化时调用[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];

navigationBar框架为0,0,320,44 navigationBar超级视图框架为0,0,320,480 viewController视图框架为0,0,320,436。

我试图在viewDidLoad self.navigationController.navigationBar.userInteractionEnabled = YES;self.navigationItem.leftBarButtonItem.enabled = YES;中调用而没有效果。

会发生什么?

编辑:
我的self.navigationController.navigationItem.backBarButtonItem是NIL。 self.navigationController.navigationItem不是NIL

3 个答案:

答案 0 :(得分:1)

每当这种反应迟钝发生在我身上时,总是因为框架问题。即NavigationController的superview小于NavigationController的视图。我知道你说所有内容都设置为全屏,但我会通过为层次结构中的每个视图打开“clipsSubviews”来验证所有内容实际上是全屏。

答案 1 :(得分:0)

我刚遇到这个问题,我不知道为什么会这样,但不是这样做:

UIBarButtonItem *backButton =
[[[UIBarButtonItem alloc] initWithTitle:@"Back"
                                  style: UIBarButtonItemStyleBordered
                                 target:nil
                                 action:nil] autorelease];

self.navigationItem.leftBarButtonItem = backButton;

我用

替换了第二行
 self.navigationController.navigationItem.leftBarButtonItem = backButton;

这对我有用。

答案 2 :(得分:0)

我找到了解决方案。 问题是第一个视图是从叠加层调用的,而不是从选择器调用的。 将Picker的引用保留到叠加层中,并从中调用视图可以解决问题:

来自叠加层:

[self.picker presentModalViewController:navController animated:YES];

作品

而不是:

[self presentModalViewController:navController animated:YES];
相关问题