setHidesBackButton不起作用

时间:2014-02-05 09:18:12

标签: ios uinavigationbar

这个让我发疯的事。 从我的根视图控制器我正在推动另一个视图控制器强制用户输入一些凭据以便登录。除非凭据不正确,否则用户将无法切换回根视图。为了实现这一点,我试图隐藏后退按钮,但由于某种原因,这不起作用。 有什么建议吗?

- (void)presentLoginWebView
{
  UIViewController *webViewController = [[UIViewController alloc] init];
  webViewController.title = NSLocalizedString(@"IB_LOG_IN_TITLE", nil);

  UIWebView *webView = [[UIWebView alloc] initWithFrame:webViewController.view.frame];
  webViewController.view = webView;

  [self.navigationController pushViewController:webViewController animated:NO];

  [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:IB_GET_OAUTH_TOKEN_URL]]];
  webView.scalesPageToFit = YES;
  webView.delegate = self; //delegate methods below

  if (deviceVersion > 6)
  {
    [self.navigationController.interactivePopGestureRecognizer setEnabled:NO];
  }
  [self.navigationController.navigationItem setHidesBackButton:YES];

  //The following line doesn't work either
  //self.presentedViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[[UIView alloc] init]];
}

2 个答案:

答案 0 :(得分:2)

以下代码可以使用。只试用navigationItem,而不是navigationController.navigationItem

webViewController.navigationItem.hidesBackButton = YES;

答案 1 :(得分:1)

尝试隐藏webViewController

的后退按钮
webViewController.navigationItem.hidesBackButton = YES;