繁体   English   中英

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

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

我有一个全屏的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未激活,我的意思是触摸它不会突出显示它,也不会返回到前一个视图。

我的视图以[[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

每当我对这种反应迟钝时,总是因为构图问题。 即NavigationController的超级视图小于NavigationController的视图。 我知道您说的是所有内容都设置为全屏,但是我将通过为层次结构中的每个视图打开“ clipsSubviews”来验证所有内容是否全屏。

我只是遇到了这个问题,我不确定为什么会这样,但是没有这样做:

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

self.navigationItem.leftBarButtonItem = backButton;

我将第二行替换为

 self.navigationController.navigationItem.leftBarButtonItem = backButton;

这对我行得通。

我找到了解决方案。 问题在于,第一个视图是从叠加层而不是选择器中调用的。 在叠加层中保留对Picker的引用,然后从中调用视图即可解决此问题:

从叠加层:

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

作品

代替:

[self presentModalViewController:navController animated:YES];

暂无
暂无

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

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