Objective-C:NSMutableString错误

时间:2010-11-16 16:07:40

标签: objective-c nsmutablestring

我一直收到这个代码的错误,应用程序告诉我我正在尝试改变一个不可变的对象。有人可以看看并解释我做错了什么吗?感谢。

thisrow = [NSString stringWithFormat:@"%i", startPointX2];
NSMutableString* setCoordStr = [[NSMutableString alloc] init];
[setCoordStr appendFormat: thisrow];

if(w==1) {
    thiscol =  [NSString stringWithFormat:@"%i", endPointY];
    [setCoordStr insertString:thiscol atIndex:[setCoordStr length]];
 } else {
    for(startPointY; startPointY<endPointY+1; startPointY++) {
        thiscol =  [NSString stringWithFormat:@"%i", startPointY];
        [setCoordStr insertString:thiscol atIndex:[setCoordStr length]];
    }
 }

NSLog(@"%@ ", setCoordStr);

1 个答案:

答案 0 :(得分:1)

您可以使用appendString:代替您的第一个appendFormat:insertString:atIndex: