我有一个名为矩阵的对象集合 (UILabel)。
例如:
A11 A12 A13 A14 ...
A21 A22 A23 A24 ...
A31 A32 A33 A34 ...
... ... ... ...
我正在考虑使用简单的 for 循环来设置文本:
for (int i=1; i==5; i++) {
for (int y=1; y==5; y++) {
//code
}
}
有办法做到那样吗?像这样的……
Aiy.text = [[NSString alloc] initWithFormat: @"A%d%d", i, y];
编辑: 可能我没有把我的问题解释清楚,对不起...
我想做这样的事情(请原谅代码亵渎!)
A(@"%d",i)(@"%d",y).text = [[NSString alloc] initWithFormat: @"A%d%d", i, y];
并将这些内容放入 for 循环中,这样我就可以更改所有标签的文本(标签 A11
将以“A11”作为文本)
最佳答案
所以你想访问给定它的属性名称的标签...
在你的循环中,尝试:
// Get label's name
NSString *name = [NSString stringWithFormat:@"A%d%d", i, y];
// Get label from class given it's name
UILabel *label = [self valueForKey:name];
// Set the contents
label.text = name;
关于iphone - 索引对象矩阵 (UILabel),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8257926/