1

我正在使用 NSDictionary 更改 appDelegate 文件中 UIBarButtonItem 的外观:

UIBarButtonItem *barButtonItemProxy = [UIBarButtonItem appearanceWhenContainedIn:
                                       [UINavigationBar class], [UINavigationController class], nil];

NSDictionary *textAttributes = @{UITextAttributeFont :
                                     [UIFont fontWithName:@"ChocoBold" size:13.0f],
                                 UITextAttributeTextColor : [UIColor whiteColor],
                                 UITextAttributeTextShadowColor : [UIColor blackColor],
                                 UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetMake(0.0f, -1.0f)]
                                 };
[barButtonItemProxy setTitleTextAttributes:textAttributes forState:UIControlStateNormal];

该应用程序在模拟器中运行良好,但是当我在设备上运行它时,应用程序崩溃并出现以下异常:

 [__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]

崩溃发生在NSDictionary *textAttributes队列中。

我不明白该字典中哪个参数为零?

4

1 回答 1

4
NSLog(@"font family %@",[UIFont fontNamesForFamilyName:@"Choco"]);

如果您的应用程序中存在 choco 字体系列,它将记录所有可用的字体名称。然后复制确切的字体名称。可能是您使用的字体名称错误,例如它的 Choco-Bold 而不是 chocobold 等。

NSMutableDictionary *textAttributes = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                       [UIColor whiteColor],UITextAttributeTextColor,
                                       [UIColor blackColor],UITextAttributeTextShadowColor,
                                       [NSValue valueWithUIOffset:UIOffsetMake(0.0f, -1.0f)],UITextAttributeTextShadowOffset,
                                       [UIFont fontWithName:@"Helvetica" size:13.0f],UITextAttributeFont,nil];

如果可以尝试使用“Helvetica”字体,那么问题出在您的字体上。

于 2013-03-09T17:43:29.803 回答