如何访问for语句中的许多UILabels? [英] How to access many UILabels inside a for statement?

查看:122
本文介绍了如何访问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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆