【问题标题】:Reloading navigation bar重新加载导航栏
【发布时间】:2014-05-26 20:10:19
【问题描述】:

如何重新加载/重新分配导航栏项目?我使用一些更改导航栏的库,有时我有一个包,其中所有导航项都消失了。我在viewWillAppear 中重新分配了正确的项目,例如:

UIButton *actionButton = [UIButton buttonWithType:UIButtonTypeCustom];
actionButton.frame = CGRectMake(270, 0, 50, 50);
actionButton.adjustsImageWhenHighlighted = YES;
[actionButton setImage:[UIImage imageNamed:@"share.png"] forState:UIControlStateNormal];
[actionButton setImage:[UIImage imageNamed:@"share-active.png"] forState:UIControlStateHighlighted];
[actionButton addTarget:self action:@selector(presentActivity) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *actionBarButton = [[UIBarButtonItem alloc]initWithCustomView:actionButton];
actionBarButton.tintColor = [UIColor whiteColor];
self.navigationItem.rightBarButtonItem = actionBarButton;

但它不起作用,有时我没有任何导航项。

【问题讨论】:

  • 你用的是什么库?您需要找出库在什么时候弄乱了您的工具栏,然后调用您的代码或阻止它发生
  • AMScrollingNavbar,它的开发者不知道会发生这种情况=/
  • 好的,您的问题中缺少一些信息。 是什么意思?您如何将视图控制器与导航控制器连接起来(假设正在使用一个情节提要)?
  • 我不认为该库有问题,因为它没有在任何地方设置 barButtonItems。

标签: ios navigation uinavigationbar uinavigationitem


【解决方案1】:
UIBarButtonItem

不是 UIButton 的子元素。

这里没有像setImage:forState: 这样的已知方法。

像这样创建和自定义一个 UITabBarButton

UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:self action:@selector(goBack)];
    newBackButton.image = [UIImage imageNamed:@"back"];
    self.navigationItem.leftBarButtonItem=newBackButton;

还验证当viewDidLoad时是否会调用带有此代码的方法

【讨论】:

    【解决方案2】:

    https://developer.apple.com/library/ios/documentation/uikit/reference/uinavigationbar_class/Reference/UINavigationBar.html 一样查看这个,苹果开发者很棒。

    这是另一个很好的链接 AppCoda 有很多很棒的教程,其中包含您需要了解的有关导航栏的所有内容 http://www.appcoda.com/customize-navigation-status-bar-ios-7/

    您还可以使用带有标识符方法的执行 segue 并将字符串或其他内容发送到新的视图控制器,然后当您看到该字符串等于您想要的字符串时,请在 viewWillAppear 方法中使用 if 语句。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-08
      • 1970-01-01
      • 2017-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多