我知道这听起来像是一个微不足道的问题,但我在 *.h 文件中定义了 50 个标签
UILabel *tempLabel1;
UILabel *tempLabel2;
UILabel *tempLabel3;
...
UILabel *tempLabel50;
在我的 *.c 文件中,我想为每个标签设置值,但我不想手动执行或一遍又一遍地写出来。
//Instead of doing this
tempLabel1.text = @"1";
tempLabel2.text = @"2";
...
tempLabel50.text = @"50";
//I would like to do something like this
//I know this isn't correct syntax but want to know if something like
//this can be done?
for (int i = 0; i < 50; i++)
{
tempLabel[i].text = @"%d", i+1;
}