我正在使用带有自定义UIView
子类的导航,该子类成为我的titleView。我想确保这是完整的可用宽度。
从我的UIViewController
viewWillAppear:
开始,这应该是:
CGFloat width = self.width - self.navigationItem.leftBarButtonItem.width - someConstant;
(我这里没有正确的项目。)
然后,这将适应leftBarButtonItem
的不同可能宽度。问题是leftBarButtonItem
是nil
,所以leftBarButtonItem.width
始终为0(好吧,无论如何都在模拟器中)。
backBarButtonItem
也是零。
我应该做什么呢?
答案 0 :(得分:4)
我通过执行以下操作来破解这个:
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;
讨厌,但它有效