I just wanted to ask how it is possible to use a variable as selector. My code looks like this:
NSString *stunde = [lesson objectForKey:@"stunde"]; // value is t1s1, then t1s2 then t1s3 etc.
t1s1.text=subject;
这毫无问题。但由于我必须循环浏览40个标签,这样做会很棒:
NSString *stunde = [lesson objectForKey:@"stunde"];
**stunde**.text=subject;
如何使用从for循环中的json字符串中获得的值来动态地与标签对话。
结果应该如下所示:
NSString *stunde = [lesson objectForKey:@"stunde"];
t1s1.text=@"English";
NSString *stunde = [lesson objectForKey:@"stunde"];
t1s2.text=@"German";
NSString *stunde = [lesson objectForKey:@"stunde"];
t1s3.text=@"Business Studies";
等
我希望你能帮助我,知道我的意思
提前感谢
更新:
我刚开始这样工作(硬编码):
labels[0] = t1s1;
labels[1] = t1s2;
labels[2] = t1s3;
for (NSDictionary *lessons in list)
{
int TotalLessons = [list count];
NSString *fach = [lessons objectForKey:@"fach"];
UILabel *stunde = [lessons objectForKey:@"stunde"];
//labels[counter]=stunde;
labels[counter].text=fach;
counter=counter+1;
if(counter>=TotalLessons){
break;
}
}
but as there will be 40-50 labels I would like to add the label_names dynamically to the array: like this:
UILabel *stunde = [lessons objectForKey:@"stunde"];
labels[counter]=stunde;
值“stunde”将被定义为UILabel,然后添加到数组中。但为什么应用程序崩溃了?怎么了?:(
谢谢