1

我有以下代码不断崩溃并且找不到原因。

@property (nonatomic)NSUInteger numberOfShapes;
@property (strong, nonatomic)NSString *shapeInCard;
@property (strong, nonatomic)UIColor *colorOfShape;
@property (nonatomic)float shadeOfColor;enter code here

- (NSAttributedString *) contents
{
    NSMutableAttributedString *cardContents = [[NSMutableAttributedString alloc] initWithString:@""];
    UIColor *shapeColor = [self.colorOfShape colorWithAlphaComponent:self.shadeOfColor];
    NSAttributedString * shapeToUse = [[NSAttributedString alloc] initWithString:self.shapeInCard attributes:@{NSBackgroundColorAttributeName:shapeColor}]; <-------
    for (int i=0; i<self.numberOfShapes; i++) {
        [cardContents appendAttributedString:shapeToUse]; <------
        if(i < self.numberOfShapes-1) {
            [cardContents appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
        }
    }
    return cardContents;
}

属性由另一种方法设置。

我在标有 <-------- 的行上不断收到此错误-[__NSCFNumber length]: unrecognized selector sent to instance 0x8b54fe0。我找不到原因。如果我消除属性部分只是在第二行崩溃,我已经设法通过第一个标记线。

有人可以帮忙吗?

提前致谢。

4

0 回答 0