gpt4 book ai didi

objective-c - 崩溃并尝试从对象中插入nil对象[0]

转载 作者:行者123 更新时间:2023-12-03 15:53:57 24 4
gpt4 key购买 nike

我正在使用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行中。

我不明白该词典中哪个参数为nil?

最佳答案

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”字体,如果它起作用,则问题出在您的字体上。

关于objective-c - 崩溃并尝试从对象中插入nil对象[0],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15313444/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com