【问题标题】:Back button covers up a previous UIBarButton when pushViewController is called调用 pushViewController 时,后退按钮会覆盖上一个 UIBarButton
【发布时间】:2014-07-17 21:45:59
【问题描述】:

我的应用通过左侧的滑出菜单进行导航。在每个viewController 的顶部是一个名为“导航”的左侧UIBarButton,当触摸它时,无需执行拖动效果即可打开滑出菜单。我在我的应用程序中实现语音命令,如果用户说“转到财务”,它会转到标题为 FianceViewControllerviewControllerinstantiateViewControllerpushViewController

这一切都很好,唯一的问题是与push segue相关的后退按钮覆盖了UINavigationBar左侧插槽中的“导航”按钮。使用self.navigationItem.hidesBackButton = YES; 隐藏后退按钮和我的“导航”按钮。无论如何,当推送发生时不会出现后退按钮,但仍然允许查看和使用我之前创建的“导航”栏按钮?或者如果这个UIBarButton 的困境无法解决,除了push 之外,我还能做什么?

说出来的代码部分:

if ([title isEqualToString:@"FINANCES"])
{

    FinanceViewController *fvc = [[self storyboard] instantiateViewControllerWithIdentifier:@"finance"];
    [[self navigationController] pushViewController:fvc animated:YES];

}

【问题讨论】:

    标签: ios uiviewcontroller segue uibarbuttonitem pushviewcontroller


    【解决方案1】:

    如何添加导航按钮? 我会在隐藏后退按钮后尝试添加它,如下所示:

    self.navigationItem.hidesBackButton = YES;
    UIButton *navigationButton = [[UIButton alloc] initWithFrame:CGRectMake(15.0, 15.0, 100.0, 32.0)];
    self.navigationController.navigationBar.backItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:navigationButton];
    

    【讨论】:

    • 我已经添加了创建导航按钮的代码。这很棘手,因为这是在 rootViewController 而不是个人 viewControllers 中声明的,所以让我知道你的想法。
    【解决方案2】:

    我没有隐藏我的后退按钮,而是发现我可以简单地在它上面写!在pushViewController 之前使用fvc.navigationItem.leftBarButtonItem = self.navigationItem.leftBarButtonItem;,允许“导航”按钮覆盖后退按钮。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-30
      • 1970-01-01
      • 2021-12-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多