如何访问for语句中的许多UILabels? [英] How to access many UILabels inside a for statement?
本文介绍了如何访问for语句中的许多UILabels?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在研究Objective-C并对此操作有疑问:
我知道快速枚举更好,但是我想知道这么做使用FOR方法。
在ActionScript 3代码中:
/ *
label0.text = [array objectAtIndex:0];
label1.text = [array objectAtIndex:1];
label2.text = [array objectAtIndex:2];
label3.text = [array objectAtIndex:3];
* /
for(int i = 0; i <4; i ++){
this [label+ i] .text = array [i];
解决方案
在代码或生成器中),然后只要打电话给他们,无论你想使用:
UILabel * myLabel =(UILabel *)[ self.view viewWithTag:i];
myLabel.text = [array objectAtIndex:i];
里面的一个当然.. goodluck:)
Possible Duplicate:
Objective C Equivalent of PHP's “Variable Variables”
I'm studding Objective-C and have a doubt about this operation:
I know that fast enumeration is better, but I would like to know do that with FOR approach.
In Actionscript 3 I code:
/*
label0.text = [array objectAtIndex:0];
label1.text = [array objectAtIndex:1];
label2.text = [array objectAtIndex:2];
label3.text = [array objectAtIndex:3];
*/
for (int i = 0; i<4; i++ ) {
this["label" + i].text = array[ i ];
}
解决方案
You need to tag them (in the code or in the builder) then just call them wherever you want using:
UILabel*myLabel = (UILabel*)[self.view viewWithTag:i];
myLabel.text = [array objectAtIndex:i];
inside a for of course.. goodluck :)
这篇关于如何访问for语句中的许多UILabels?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文