崩溃与异常尝试从对象插入nil对象[0] [英] Crash with exception attempt to insert nil object from objects[0]

查看:238
本文介绍了崩溃与异常尝试从对象插入nil对象[0]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

NSDictionary * textAttributes = @ {UITextAttributeFont:
[UIFont fontWithName:@ChocoBoldsize: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:]:尝试从对象插入nil对象[0] 

崩溃发生在 NSDictionary * textAttributes >

我不明白该字典中的哪个参数是nil?

解决方案

$ p> NSLog(@font family%@,[UIFont fontNamesForFamilyName:@Choco]);

如果choco字体系列存在于您的应用程序中,它会记录所有可用的字体名称。然后复制确切的字体名称。
可能是您使用的字体名称是错误的。

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

尝试使用Helvetica字体,如果它的工作,那么问题是与您的字体。


I'm using NSDictionary to change the appearance of UIBarButtonItem in the appDelegate file:

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];

The app works fine in the simulator but when I run it on a device the app crashes with the following exception:

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

The crash happens in NSDictionary *textAttributes line.

I don't understand which parameter is nil in that dictionary?

解决方案

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

If choco font family exists in your app than it will log all the available font names. Then copy the exact font name. May be the font name you are using is wrong e.g. its Choco-Bold instead of chocobold etc.

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];

Try with the "Helvetica" font if it works then the problem is with your font.

这篇关于崩溃与异常尝试从对象插入nil对象[0]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆