ios - 如何解决 NSInvalidArgumentException 错误?

标签 ios objective-c iphone xcode

对于用户来说,我的应用会间歇性崩溃,但不幸的是,我无法在我的任何设备上重现该问题。报错是:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSConcreteAttributedString initWithString:: nil value'

日志跟踪不清楚崩溃源。 我附上了日志跟踪。 我正在寻找任何可以帮助我追踪这一点的指示。

screenshot of sample exception

最佳答案

崩溃的原因在你的标题中...

原因:'NSConcreteAttributedString initWithString::零值'

看起来您正在尝试从字符串创建属性字符串,但该字符串为 nil。

在你执行 NSAttributeString initWithString 之前添加一个守卫以确保字符串不为零,即

if (string) {
    NSAttributedString *attributedString = [[NSAttributedString alloc] initWithAttributedString:string];

    //other code etc...
}

关于ios - 如何解决 NSInvalidArgumentException 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35316883/

相关文章:

objective-c - 如何在 Cocoa 的窗口内处理 mousedown 事件

iphone - 应用提交,图标大小错误由于即将发布的IOS7

ios - 检测两个日期是否在同一日历日内

ios - CGRectMake 已移到我的导航栏后面

ios - 如何在 Swift 或 Objective C 中使用 PKCS8 RSA DER 私钥

iOS : subview of a button not showing up

iphone - 当模型改变时删除存储在 CoreData 中的所有数据

iphone - 编写一个 "No Photos In Albums"屏幕

php - 为什么 Mobiledetect.net 脚本无法检测到 iPhone?

ios - Swift 3 - 如何让计时器在后台工作