【发布时间】:2014-08-06 18:01:58
【问题描述】:
我正在使用数组“allscores”来解析填充表格行中的文本标签“scorelbl”。
cell.scorelbl.text = [allscores objectAtIndex:[indexPath row] - 1];
数组打印
1
2
3
2
etc
但我想在每个字符串中包含“/5”,以便在单元格中打印:
1/5
2/5
3/5
2/5
etc
然后我用它来替换数组中的字符串:
for (int i=0; i<[allscores count]; i++) {
NSString* string = [allscores objectAtIndex:i];
NSString * scorestringformatted = [NSString stringWithFormat:@"%@/5", string];
[allscores replaceObjectAtIndex:i withObject:scorestringformatted];
}
我正在尝试,但它打印:
1/5
2/5/5
3/5/5/5
2/5/5/5/5
etc
我应该解决什么问题?
建议解决方案的更新结果:
当我为每一行打印它们时,/5 会不断增加。它从所需的开始并结束
scores:
3/5/5/5/5/5/5,1/5/5/5/5/5/5,1/5/5/5/5/5/5,1/5/5/5/5/5/5,1/5/5/5/5/5/5,1/5/5/5/5/5/5,1/5/5/5/5/5/5,1/5/5/5/5/5/5,2/5/5/5/5/5/5,1/5/5/5/5/5/5,1/5/5/5/5/5/5,1
result: (
"3/5/5/5/5/5/5/5",
"1/5/5/5/5/5/5/5",
"1/5/5/5/5/5/5/5",
"1/5/5/5/5/5/5/5",
"1/5/5/5/5/5/5/5",
"1/5/5/5/5/5/5/5",
"1/5/5/5/5/5/5/5",
"1/5/5/5/5/5/5/5",
"2/5/5/5/5/5/5/5",
"1/5/5/5/5/5/5/5",
"1/5/5/5/5/5/5/5",
1
)
allscores: (
"3/5/5/5/5/5/5/5",
"1/5/5/5/5/5/5/5",
"1/5/5/5/5/5/5/5",
"1/5/5/5/5/5/5/5",
"1/5/5/5/5/5/5/5",
"1/5/5/5/5/5/5/5",
"1/5/5/5/5/5/5/5",
"1/5/5/5/5/5/5/5",
"2/5/5/5/5/5/5/5",
"1/5/5/5/5/5/5/5",
"1/5/5/5/5/5/5/5",
1
)
【问题讨论】:
-
什么时候调用该方法是个问题。另外,为什么在使用数据时(即在单元格上设置文本时)更改源数据而不是仅仅应用格式?
标签: objective-c replace nsstring nsarray