views:

622

answers:

1

I am using navigation with a custom UIView subclass that becomes my titleView. I want to ensure this is the full available width.

Logically from my UIViewController's viewWillAppear:, this should be:

CGFloat width = self.width - self.navigationItem.leftBarButtonItem.width - someConstant;

(I don't have a right item here.)

This would adapt, then, for different possible widths of the leftBarButtonItem. The catch is that leftBarButtonItem is nil, so leftBarButtonItem.width is always 0 (well, in the simulator anyway).

backBarButtonItem is also nil.

What should I be doing instead?

+2  A: 

I hacked this by doing the following:

    int vcStackSize = [[self.navigationController viewControllers] count];
    WEViewController* previousController = [[self.navigationController viewControllers] objectAtIndex:vcStackSize - 2];

    NSString* previousTitle = [previousController title];

    UIFont* font = [UIFont boldSystemFontOfSize:12];


    lw = [previousTitle sizeWithFont:font].width + 26;

Nasty but it works

Sam