开发者

navigationBar color and title

I had a lot of .xib files and I try to recreate them programmatically.

The only problem is, is that I can't customize my navigationbar a开发者_StackOverflow中文版ny more.

De versions function is called by another view with multiple bar button items, so the code is generic to other functions to.

- (void)versions
{
    VersionsViewController *verController = [[VersionsViewController alloc] initWithDocument:document];
    [verController setDelegate:self];

    [self loadPopupView:verController];

    [verController release];
}

- (void)loadPopupView:(UIViewController *)viewController
{
    if (popOverController != nil && [popOverController isPopoverVisible]) 
    {
        [popOverController dismissPopoverAnimated:YES];
    }

    if(![popOverController isPopoverVisible] || ![popOverController.contentViewController isKindOfClass:[viewController class]])
    {
        popOverController = [[UIPopoverController alloc] initWithContentViewController:viewController];
        popOverController.popoverContentSize = CGSizeMake(320, 500);

        UIBarButtonItem *buttonLocation;

        if([viewController isKindOfClass:[CommentaryViewController class]])
            buttonLocation = commentaryButton;
        else if([viewController isKindOfClass:[PropertiesViewController class]])
            buttonLocation = propertiesButton;
        else
            buttonLocation = versionsButton;

        [popOverController presentPopoverFromBarButtonItem:buttonLocation permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    }
}

VersionsViewController.m

- (id)initWithDocument:(Document *)doc
{
    self = [super init];

    if(self)
    {
        self.document = doc;
        self.title = @"other title"; //does not work either

        //I just tried everything I could think of :P
        self.navigationController.navigationBar.tintColor = [UIColor orangeColor];
        self.navigationItem.titleView.backgroundColor = [UIColor redColor];
        self.navigationController.navigationItem.titleView.backgroundColor = [UIColor greenColor];
        self.navigationController.tabBarController.tabBar.backgroundColor = [UIColor blueColor];
        self.navigationController.navigationBar.backgroundColor = [UIColor purpleColor];
    }

    return self;
}

Can someone see what I did wrong?

EDIT:

NSLOG from self.title and self.navigationController.title are both 'null'

When I create a navigationController add the view and add the navigationController to the popup i get 2 bars and then I can set the title of the navigationController but still not the color.


Just curious: if you have working nib files, why are your recreating them programmatically?

In initWithDocument:, you haven't assigned a nvaigationController yet. You'll need to build one of those by hand, and install VersionViewController in it (navigationController will be set after you've done that). Having all of this work automatically is one of the reasons we use nib files.

EDIT Anytime "nothing happens" check that the object you're messaging is not nil. I'm certain navigationController is still nil when you get to it. You should also NSLog the objects you care about and look at their addresses. You probably are accidentally creating multiple views or multiple navigation controllers. This is very common to do when you try to build this stuff by hand. Nibs are the correct solution in most cases.


- (void)versions
{
    VersionsViewController *verController = [[VersionsViewController alloc] initWithDocument:document];
    [verController setDelegate:self];
    UINavigationController *navC = [[UINavigationController alloc] initWithRootViewController:verController];
    [self loadPopupView:navC];
    [verController release];
    [navC release];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜