我确定 mutable 意味着它可以更改,那么为什么会发生这种情况?
attrString = [[NSMutableAttributedString alloc] initWithString:@"Tip 1: Aisle Management The most obvious step – although one that still has not been taken by a disconcerting number of organisations – is to configure cabinets in hot and cold aisles. If you haven’t got your racks into cold and hot aisle configurations, we can advise ways in which you can achieve improved airflow performance."];
[attrString setFont:[UIFont systemFontOfSize:20] range:NSMakeRange(0, 23)];
[attrString setFont:[UIFont systemFontOfSize:15] range:NSMakeRange(24, 325)];
[attrString setTextColor:[UIColor blackColor] range:NSMakeRange(0,184)];
[attrString setTextColor:[UIColor blueColor] range:NSMakeRange(185,325)];
break;
我的 cattextlayer 和我的 nsmutableattributedsring 都在我的头文件中定义。我在开关中对上面的字符串进行了更改,然后调用此代码来更新字符串显示在的 cattextlayer:
//updates catext layer
TextLayer = [CATextLayer layer];
TextLayer.bounds = CGRectMake(0.0f, 0.0f, 245.0f, 290.0f);
TextLayer.string = attrString;
TextLayer.position = CGPointMake(162.0, 250.0f);
TextLayer.wrapped = YES;
[self.view.layer addSublayer:TextLayer];
它在尝试设置字体时崩溃,但我不知道为什么?
-[NSConcreteMutableAttributedString setFont:range:]:无法识别的选择器发送到实例 0xd384420 *由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[NSConcreteMutableAttributedString setFont:range:]:无法识别的选择器发送到实例 0xd384420”
为什么会这样?