Apidata在阵列,但阵列中的数据不是在文本框中显示
问题描述:
NSString *stringForTextView = @"";
for(NSDictionary *d in _arr1)
{
stringForTextView = [NSString stringWithFormat:@"CellId:%@\nLacId:%@\nLattitude:%@\nLongitude:%@\nDistance:%@\nAddress:%@\n", [d valueForKey:@"cid"],[d valueForKey:@"lac"],[d valueForKey:@"lat"], [d valueForKey:@"long"], [d valueForKey:@"distance"],[d valueForKey:@"address"]];
}
txtcellview.text = stringForTextView;
只有最后一个记录显示....所有记录中的TextView没有表现出ARR但ARRY数据Apidata在阵列,但阵列中的数据不是在文本框中显示
apidata只在文本框
不显示
答
”最后一个记录显示....“
这是因为你不断地分配相同的变量,循环的每次迭代,所以最后分配的任何内容都将保留。
我不能确定你想要什么,但你可能要保持每个元素追加到一个字符串:
NSMutableString *stringForTextView = [NSMutableString new];
for(NSDictionary *d in _arr1)
{
[stringForTextView appendString:[NSString stringWithFormat:@"CellId:%@\nLacId:%@\nLattitude:%@\nLongitude:%@\nDistance:%@\nAddress:%@\n", [d valueForKey:@"cid"],[d valueForKey:@"lac"],[d valueForKey:@"lat"], [d valueForKey:@"long"], [d valueForKey:@"distance"],[d valueForKey:@"address"]]];
}
txtcellview.text = stringForTextView;
请注意,此代码不添加元素之间的分隔符;我会把它留给你...
追加文字到'stringForTextView'而不是每次重新创建。 – Larme