Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 错误:';尝试使用appendString:'--_Iphone_Objective C_Nsmutablearray_Nsmutablestring - Fatal编程技术网

Iphone 错误:';尝试使用appendString:'--

Iphone 错误:';尝试使用appendString:'--,iphone,objective-c,nsmutablearray,nsmutablestring,Iphone,Objective C,Nsmutablearray,Nsmutablestring,我犯了一个错误 '尝试使用appendString:更改不可变对象' 我的代码是 NSMutableString *resultString= [[NSMutableString alloc]init]; for (NSMutableString *s in self.ArrayValue) { [resultString appendString:s]; NSLog(resultString); } ArrayValue是NSMutableArray。 我不明白问题

我犯了一个错误 '尝试使用appendString:更改不可变对象'

我的代码是

NSMutableString *resultString= [[NSMutableString alloc]init];


for (NSMutableString *s in self.ArrayValue)
{
    [resultString appendString:s];
    NSLog(resultString);

}  
ArrayValue是NSMutableArray。
我不明白问题出在哪里


提前谢谢您

请务必这样做:

它对我有用

    NSMutableString *resultString= [[NSMutableString alloc]init];
NSMutableArray *ArrayValue=[[NSMutableArray alloc]init];
[ArrayValue addObject:@"One"];
[ArrayValue addObject:@"Two"];
[ArrayValue addObject:@"Three"];

for (NSMutableString *s in ArrayValue)
{
    [resultString appendString:s];
    NSLog(@"%@",resultString);------->You should use %@ to print the string otherwise will show your warning.

}  
控制台上的O/p:

2011-03-08 19:13:02.243 iPadTables[4557:207]一个

2011-03-08 19:13:06.224 iPadTables[4557:207]一对


2011-03-08 19:13:09.388 iPadTables[4557:207]一个三个

发布时,您的代码不会给出您描述的错误。很可能,在分配resultString和for循环之间的某个地方,您正在使用正常的NSSring覆盖它

    ArrayValue = [NSMutableArray arrayWithObjects:@"b",@"o",@"n",nil];
NSMutableString *resultString= [[NSMutableString alloc]init];

for (NSMutableString *s in self.ArrayValue)
{
    [resultString appendString:s];
    NSLog(resultString);

}  

对我有效。

当您减少代码以便发布代码时,您应该确保您发布的代码片段与整个代码的结果相同。数组值来自web服务器,我在其他视图中使用相同的方法,其工作方式是正确的。我正在执行“resultString=@”;,它给了我一个错误