문제

Okay, there's one thing I really don't understand.

I have a navigation controller (created in AppDelegate.m) as the first item in a tab bar controller (created in AppDelegate.h):

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

In another class, I access this tabOneNavigationController by:

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

And if I want to change the background of navtab1's navigation bar, I write:

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

But for changing titleView, I've only seen examples using:

self.navigationItem.titleView = ...

but how do I do change navtab1's titleView?

Example: I have a custom TableViewCell, which contains a button, and when that button's clicked, it should change the titeView of navtab1 (in this case, self obviously doesn't have navigationItem property.

올바른 솔루션이 없습니다

다른 팁

Here is use delegate methode of UINavigationController, This code might be helpful in your case:

#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];

}

In above Method you also put image/color of NavigationBar.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top