5

有什么方法可以让我拥有一个并且无论它被推送多少次UINavigationController都始终显示相同?UIBarButtonItem

4

4 回答 4

1

尝试这个-

  1. 创建子类(CustomNavigationControllerUINavigationController并使用它来推送您的视图控制器。
  2. CustomNavigationController创建UIBarButtonIteminit或中viewDidLoad。添加target&action到它。
  3. 在委托方法中为每个视图控制器实现UINavigationControllerDelegate委托CustomNavigationController并设置barButtonYouCreated为右栏或左栏按钮项。

利用

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
     viewController.navigationItem.leftBarButtonItem = barButtonYouCreated;
}

或者

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
于 2012-11-21T02:45:18.833 回答
0

或者尝试使用 UINavigationController 类别,并自定义 back item,这样无论推送多少次,都只需为 navigationController 的 back item 设置相同的视图。就像是:

@implementation UIViewController (CustomNavigation)

- (void)setLeftBarButtonItem:(UIButton*)leftview
{    
    UIBarButtonItem *customItem = [[[UIBarButtonItem alloc] initWithCustomView:leftview] autorelease];
    self.navigationItem.leftBarButtonItem = customItem; 
    [(UIButton*)self.navigationItem.leftBarButtonItem.customView addTarget:self.navigationController action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];
}
于 2012-11-21T04:14:38.690 回答
0

您可以使用UINavigationControllerDelegate如下:

- (void)navigationController:(UINavigationController *)navigationController 
      willShowViewController:(UIViewController *)viewController animated:(BOOL)animated

在此委托方法中,您可以检查是否将 barButtonItem 添加到导航栏。

于 2012-11-21T03:18:15.547 回答
0

您可以创建一个包含您的推送控制器的全局,然后隐藏您的UITabBarController推送控制器UINavigationControllernavigationbar

于 2012-11-21T03:39:29.600 回答