好的,所以我试图使用数组和for循环给出7个不同的标签名称。
代码:
id huller[] = {hul18.text, hul17.text, hul16.text, hul15.text, hul14.text, hul13.text, hul12.text, hul11.text, hul10.text, hul9.text, hul8.text, hul7.text, hul6.text, hul5.text, hul4.text, hul3.text, hul2.text, hul1.text};
for (int i = 0; 7 > i; i++) {
huller[i] = [NSString stringWithFormat:@"%i", x + 1];
NSLog(@"%@", huller[i]);
}
NSLog中的名称更改,但它们在模拟器中不会更改。有什么问题?
答案 0 :(得分:0)
如果您想要更改文本,则必须手动设置文本。
NSArray *labels = //Array of labels;
for (int i = 0; 7 > i; i++) {
huller[i] = [NSString stringWithFormat:@"%i", x + 1];
labels[i].text = huller[i];
NSLog(@"%@", huller[i]);
}
答案 1 :(得分:0)
假设hul18,hul17等都是UILabel对象,那么这样做:
NSArray *labels = [ hul18, hul17, hul16, hul15, hul14, hul13, hul12, hul11, hul10, hul9, hul8, hul7, hul6, hul5, hul4, hul3, hul2, hul1 ];
// Change the text of every label in the array
for (int i = 0; i < labels.count; i++) {
UILabel *label = labels[i];
label.text = [NSString stringWithFormat:@"%i", x + 1]; // Do you really want 'x' here or 'i'?
NSLog(@"%@", label.text);
}