0

好吧,有一件事我真的不明白。

我有一个导航控制器(在 AppDelegate.m 中创建)作为标签栏控制器(在 AppDelegate.h 中创建)中的第一项:

self.tabBarController.viewControllers = @[tabOneNavigationController, viewController2, viewController3, viewController4, viewController5];

在另一个类中,我通过以下方式访问此 tabOneNavigationController:

AppDelegate *apd = (AppDelegate *) [[UIApplication sharedApplication] delegate];
UINavigationController *navtab1 = [apd.tabBarController.viewControllers objectAtIndex:0];

如果我想改变 navtab1 导航栏的背景,我会写:

[navtab1.navigationBar setBackgroundImage:navigationBackgroundImage forBarMetrics:UIBarMetricsDefault]; 

但是对于更改titleView,我只看到使用以下示例:

self.navigationItem.titleView = ...

但是如何更改 navtab1 的 titleView?

示例:我有一个自定义 TableViewCell,其中包含一个按钮,当单击该按钮时,它应该更改 navtab1 的 titeView(在这种情况下,self 显然没有 navigationItem 属性。

4

1 回答 1

0

这是使用委托方法UINavigationController,此代码可能对您的情况有所帮助:

#pragma mark -
#pragma mark - UINavigationController Delegate Methods

- (void)navigationController:(UINavigationController *)navigationController  willShowViewController:(UIViewController *)viewController  animated:(BOOL)animated
{
    UINavigationBar *morenavbar = navigationController.navigationBar;
    UINavigationItem *morenavitem = morenavbar.topItem;
    morenavitem.titleView = myCustomeView; // Add Here your custom UIView.
    morenavitem.rightBarButtonItem.tintColor = [UIColor blackColor];

}

在上述方法中,您还放置了NavigationBar.

于 2013-07-12T08:41:32.970 回答