iphone - 索引对象矩阵 (UILabel)

标签 iphone objective-c ios for-loop uilabel

我有一个名为矩阵的对象集合 (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/

相关文章:

iOS 8 - 无法安装企业应用程序

iphone - View Controller 上的 TableView Controller

ios - 带有 NSAttributedString 的 Cell 使 UITableView 的滚动变慢

ios - CGContextClipToMask 不剪辑

angularjs - 错误: SyntaxError: DOM Exception 12 setRequestHeader@[native code]

iphone - 从 superView 中删除 UIView

objective-c - 如何使用单独的sheetController显示不同NIB包含的工作表

ios - 如何通过自动布局 xib 自动调整 UITableViewCell 的大小以填充所有设备?

ios - UIScrollView 缩放不能正常工作

ios - statusBarStyle 没有改变?