【问题标题】:Custom Image in navigationbar hiding the custom navigationbar buttons导航栏中的自定义图像隐藏自定义导航栏按钮
【发布时间】:2011-12-29 11:26:39
【问题描述】:

首先我解释我在做什么。我创建了一个基于导航的应用程序。我必须在导航栏中添加自定义图像。我使用 -

添加了图像

[self.navigationController.navigationBar insertSubview:image atIndex:0];

在此之后,我在同一个视图的导航栏左右添加了两个自定义按钮。我有另一个视图,在这个视图上,我还在导航栏左右添加了两个自定义按钮。到目前为止一切都很好,但是当我导航到我的第二个视图时,我添加到 viewwillappear 上的导航控制器的自定义按钮没有显示。我使用此代码将自定义按钮添加到导航栏 -

UIBarButtonItem *customHome = [[UIBarButtonItem alloc] initWithCustomView: buttonHome];
[self.navigationController.navigationItem setLeftBarButtonItem:customHome];

请指出这有什么问题。 :(

【问题讨论】:

    标签: uinavigationcontroller uibarbuttonitem uinavigationitem


    【解决方案1】:

    您正在尝试在导航控制器而不是视图控制器上设置 navigationItem。

    【讨论】:

      【解决方案2】:

      如果您已将 UIViewController 嵌入到 UINavigationController 中,则可以在视图控制器的 viewDidLoad 中,例如,将标题设为 UISearchBar(您在 Xcode IB 中将其拖到 UIViewController ) 并在右侧放置 2 个按钮,如下所示:

          UIBarButtonItem *componentsButton = [[UIBarButtonItem alloc] initWithTitle:@"components" style:UIBarButtonItemStylePlain target:self action:@selector(componentsButtonTapped:)];
          UIBarButtonItem *settingsButton = [[UIBarButtonItem alloc] initWithTitle:@"settings" style:UIBarButtonItemStylePlain target:self action:@selector(settingsButtonTapped:)];
          self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:componentsButton, settingsButton, nil];
          self.navigationItem.titleView = searchBar;
      

      这里的问题是管理UINavigationBar 的UINavigationController 和您和UINavigationController 共同管理的UINavigationItem 之间的区别。 (不要忘记UINavigationBarDelegate 协议,它使用的方法很少但很有用。)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-09-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多