【发布时间】:2014-01-15 04:07:30
【问题描述】:
执行将所有 NavigationItem 标题截断为特定字符数的规则的最佳方法是什么?
到目前为止,我看到的情况如下:
继承UINavigationController 并让应用程序中的所有UINavigationControllers 继承并使用此方法
@interface MyNavController : UINavigationController {
@end
@implementation MyNavController
- (void)setTitle:(NSString *)title {
// do the truncation here, but it's not working
[super setTitle:myTruncatedTitle];
}
@end
当然,只要此导航控制器中的视图控制器调用 self.title = ...,它就会进入此方法。
但它没有将这个新的截断标题设置为出现在导航栏中的标题。
或者我找到了这个解决方案,它涉及UINavigationItem 上的一个类别和 swizzling:
Make all instances of UINavigationBar titles lowercase without subclassing?
您还有其他可以建议的解决方案吗?
【问题讨论】:
-
您的所有 ViewController 是否都使用 MyNavController 导航类推送?此外,您的继承代码中有一个拼写错误: UINavigation 应该是 UINavigation
-
谢谢,没有从我的实际代码中复制。为了回答你的问题,是的,他们被推到了这个导航控制器中。
标签: ios iphone objective-c cocoa-touch uinavigationcontroller