我发现了xcode 4.5和sdk 6.0的另一个烦人的错误: 当我运行以下代码时:
UIColor *newcolor = [UIColor colorWithCIColor:[CIColor colorWithString:@"1 1 1 1"]];
[button setTitleColor:newcolor forState:UIControlStateNormal];
UILabel *lbl = selectedbutton.titleLabel;
它总是因错误而失败:
-[UICIColor colorSpaceName]: unrecognized selector sent to instance 0xa9864f0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UICIColor colorSpaceName]: unrecognized selector sent to instance 0xa9864f0'
*** First throw call stack: [...]
libc++abi.dylib: terminate called throwing an exception
答案 0 :(得分:1)
我找到了一个解决方法: 在使用我的colorWithCIColor之前,我用它做了一个副本:
newcolor = [UIColor colorWithCGColor:newcolor.CGColor];
它解决了崩溃问题。 奇怪,无论如何
答案 1 :(得分:0)
我遇到的情况与你在RGB UIColor的一系列成分值的情况相同
虽然使用CIColor colorWithString:更加紧凑,可以摆脱我手动转换的错误:
NSArray * colorParts = [color componentsSeparatedByString: @" "];
CGFloat red = [[colorParts objectAtIndex:0] floatValue];
CGFloat green = [[colorParts objectAtIndex:1] floatValue];
CGFloat blue = [[colorParts objectAtIndex:2] floatValue];
CGFloat alpha = [[colorParts objectAtIndex:3] floatValue];
UIColor * newColor = [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
[button setTitleColor:newcolor forState:UIControlStateNormal];
这当然不是最优雅的方式,但如果在更新后突然出现问题,这是一个很好的解决方法。