好吧,有一件事我真的不明白。
我有一个导航控制器(在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属性。
发布于 2013-07-12 16:41:33
下面是使用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的图像/颜色。
https://stackoverflow.com/questions/17610639
复制相似问题