views:

55

answers:

0

I'm probably doing something wrong here because this looks a bit stupid.
I'm setting up a custom titleView (in the form of a UILabel) on my UINavigationController that is the same on every page. To facilitate this, I've created a function in my app delegate to display the label correctly. I then call this function on any subviews just after I push it to the navigation stack.
Here's the code (which probably makes more sense than my explanation):

//In MyAppDelegate.m:
- (void)showTitleForNavigationController:(UINavigationController*) navController {
    UILabel *label = [[UILabel alloc] init];
    // set up label attributes
    // ...
    [label sizeToFit]; //without this line my label won't show at all
    [navController.navigationBar.topItem setTitleView:label];
    [label release];
}

// In SomeViewController.m, when pushing another controller onto the stack:
    UIViewController *otherViewController = //initialize other view controller;
    [self.navigationController pushViewController:otherViewController animated:YES];
    [(MyAppDelegate*)[[UIApplication sharedApplication] delegate] showTitleForNavigationController:otherViewController.navigationController];

My problem is that when I push the next view controller onto the stack, and the new controller slides across smoothly, for the whole duration of the animation the label sticks to the top left before finally snapping into place after the animation is finished. It looks really odd and ugly. How can I set up the label properly so that it slides from the next view smoothly? Surely it's something simple that I'm missing...