我正在尝试设置一个NSMutablearray,但总是得到空值,它不会在迭代中使用不同的值进行更新。代码如下:
NSMutableString *tipo = [NSMutableString stringWithString:@""];
if (self.canas.on){
[tipo stringByAppendingString: @"0"];
}
if (self.copas.on){
if ([tipo length]==0){
[tipo stringByAppendingString: @"1"];
}else{
[tipo stringByAppendingString:@",1"];
}
}
if (self.comer.on){
if ([tipo length]==0){
[tipo stringByAppendingString: @"2"];
}else{
[tipo stringByAppendingString:@",2"];
}
}非常感谢
发布于 2012-05-20 21:50:05
因为您应该使用appendString:方法,而不是stringByAppendingString:。
不同之处在于,第一个不会将参数附加到接收器,而第二个只是返回这样的值(接收器保持不变)。第二个消息可以发送到NSString,而第一个消息仅用于NSMutableString。
希望你能看到不同之处。
https://stackoverflow.com/questions/10673919
复制相似问题