设置UIBarButtonItem的属性字典时崩溃

时间:2015-06-19 15:42:11

标签: objective-c nsdictionary

我有以下代码:

UIFont * applicationBolFontOfSize26=[fontsSuperclass returnApplicationMainFontOfSize:26.0f];
[self.settingsButton setTitleTextAttributes:@{ NSFontAttributeName : applicationBolFontOfSize26 } forState:UIControlStateNormal];

其中font超类方法定义为:

+(UIFont *)returnApplicationMainFontOfSize:(CGFloat)floatSize {
    return [UIFont fontWithName:@"HelveticaNeue-Regular" size:floatSize];
}

但是self.settingButton setTitleText...崩溃并出现错误:

  

*由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'* - [__ NSPlaceholderDictionary initWithObjects:forKeys:count:]:尝试从对象[0]'

为什么?

1 个答案:

答案 0 :(得分:3)

没有名为“HelveticaNeue-Regular”的字体,因此您的字体为nil。使用[UIFont fontWithName:@"HelveticaNeue" size:floatSize]作为常规Helvetica Neue字体。