ios - FontAwesomeKit - 'NSInvalidArgumentException' iOS 7.1.1

标签 ios iphone objective-c nsattributedstring font-awesome

我正在为我的新 iOS 应用程序使用很酷的库 FontAwesomeKit ( https://github.com/PrideChung/FontAwesomeKit )。但是我遇到了一个奇怪的异常,它只在 Release模式和我的 iOS 7.1.1 iPhone 上抛出。

看起来像:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: 'NSConcreteMutableAttributedString addAttribute:value:range:: nil value'

当我在模拟器(DEBUG 和 RELEASE)和 iPhone(DEBUG)中测试时一切正常,iPhone(RELEASE)崩溃。

此解决方法没有帮助 - https://github.com/PrideChung/FontAwesomeKit/blob/master/KnownIssues.md

谢谢!

更新

问题出在我的代码和__weak 引用:

__weak UIColor *menuColor = [UIColor colorWithHexString:@"#636577"];
__weak UIColor *menuColorHover = [UIColor colorWithHexString:@"#3D3F52"];
CGFloat icon_size = 25.5f;

for (UIButton *button in self.buttons) {
    if ([button.titleLabel.text isEqualToString:@"Feed"]) {
        FAKFoundationIcons *feedIcon = [FAKFoundationIcons homeIconWithSize:icon_size];

        [feedIcon addAttribute:NSForegroundColorAttributeName value:menuColor];
        [button setImage:[feedIcon imageWithSize:CGSizeMake(icon_size, icon_size)] forState:UIControlStateNormal];

        [feedIcon addAttribute:NSForegroundColorAttributeName value:menuColorHover];
        [button setImage:[feedIcon imageWithSize:CGSizeMake(icon_size, icon_size)] forState:UIControlStateHighlighted];
    }

最佳答案

那里不需要__weak

正如您在评论中所说,它在调试版本中工作,因为没有进行任何优化,但在发布版本中,编译器决定优化掉弱引用,留下 nil 作为争论。

只要去掉不必要的 __weak 修饰符就可以了。

关于ios - FontAwesomeKit - 'NSInvalidArgumentException' iOS 7.1.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23583431/

相关文章:

ios - 在 cellForRowAt 中手动触发 didSelectRowAtIndexPath 会导致实际 didSelectRowAtIndexPath 委托(delegate)方法中的单元格为零

iphone - 覆盖单个单元格或部分的 tableView.separatorStyle

iphone - UITableViewRowAnimationBottom 不适用于最后一行

iphone - iOS 6 应用程序 - 如何处理 iPhone 5 的屏幕尺寸?

objective-c - NSInvalidArgumentException',原因 : '-[__NSCFString isFileURL]: unrecognized selector sent to instance 0x712e450'

iOS 应用内购买收据验证 - 如果服务器出现故障会怎样?

iphone - 使用 CGContextRef 绘图

iphone - NSURLConnection 是否阻塞主/UI 线程

ios - Objective-C iOS7检测事件的电话和麦克风可用性

objective-c - iOS 8 Mapview 当前位置不开火