简体   繁体   English

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

[英]iPhone - Navigation bar Back button item is not responding

I have a fullscreen modalView called like this: 我有一个全屏的modalView,如下所示:

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

Then from this modalView I push another view : 然后从这个modalView我推另一个视图:

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

In this new controller, I have this viewDidLoad : 在这个新的控制器中,我有这个viewDidLoad:

- (void)viewDidLoad {
    [super viewDidLoad];

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

The leftBarButtonItem is not active, I mean touching it does not highlight it nor does it go back to the previous view. leftBarButtonItem未激活,我的意思是触摸它不会突出显示它,也不会返回到前一个视图。

My views are displayed fullScreen, with [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; 我的视图以[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; called at the application initialisation. 在应用程序初始化时调用。

The navigationBar frame is 0,0,320,44. navigationBar框架为0,0,320,44。
The navigationBar superview frame is 0,0,320,480. navigationBar超级视图框架为0,0,320,480。
The viewController view frame is 0,0,320,436. viewController视图框架为0,0,320,436。

I've tried to call in viewDidLoad self.navigationController.navigationBar.userInteractionEnabled = YES; 我试图在viewDidLoad中调用self.navigationController.navigationBar.userInteractionEnabled = YES; and self.navigationItem.leftBarButtonItem.enabled = YES; self.navigationItem.leftBarButtonItem.enabled = YES; without effect. 没有效果。

What happens? 怎么了?

EDIT : 编辑:
My self.navigationController.navigationItem.backBarButtonItem is NIL. 我的self.navigationController.navigationItem.backBarButtonItem是NIL。 self.navigationController.navigationItem is not NIL self.navigationController.navigationItem不是NIL

Whenever this sort of unresponsiveness happens to me, it is always because of framing issues. 每当我对这种反应迟钝时,总是因为构图问题。 ie the superview of the NavigationController is smaller than the NavigationController's view. 即NavigationController的超级视图小于NavigationController的视图。 I know you say that everything is set to full screen, but I would verify that everything is actually full screen by turning "clipsSubviews" on for each view in the hierarchy. 我知道您说的是所有内容都设置为全屏,但是我将通过为层次结构中的每个视图打开“ clipsSubviews”来验证所有内容是否全屏。

I just had this issue, I'm not sure why this works, but instead of doing: 我只是遇到了这个问题,我不确定为什么会这样,但是没有这样做:

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

self.navigationItem.leftBarButtonItem = backButton;

I replaced the second line with 我将第二行替换为

 self.navigationController.navigationItem.leftBarButtonItem = backButton;

That works for me. 这对我行得通。

I found the solution. 我找到了解决方案。 The problem was that the first view was called from the overlay, and not from the picker. 问题在于,第一个视图是从叠加层而不是选择器中调用的。 Keeping a reference to the Picker into the overlay, and calling the view from it solves the problem: 在叠加层中保留对Picker的引用,然后从中调用视图即可解决此问题:

From the overlay: 从叠加层:

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

works 作品

instead of: 代替:

[self presentModalViewController:navController animated:YES];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM