ios - 使用标记符号 objective-c 将文本分配给 UILabel

标签 ios objective-c tags uilabel

我使用 for 循环创建了 5 个 UILabels,我已将每个项目标签设置为循环计数。我在 viewdidload 方法中执行此操作,但稍后我尝试使用 .tag

将值分配给 UILabels 之一

这是我创建 UILabel 的方法

for (int i = 0; i < 5; i++) {
  finishingCopyWidthLabel = [[UILabel alloc] initWithFrame:CGRectMake((i * quickSelectionBarSectionWidth)-180, 2.0, 100.0, 20.0)];
  finishingCopyWidthLabel.backgroundColor = [UIColor clearColor];
  finishingCopyWidthLabel.textAlignment = NSTextAlignmentCenter;
  finishingCopyWidthLabel.text = @"";
  finishingCopyWidthLabel.tag = i;

[quickSelectionBar addSubview:finishingCopyWidthLabel];
    }

然后这就是我尝试将文本分配给 UILable 的方式,但是它不起作用,任何帮助使分配工作的帮助都很棒。

UILabel *fCopyWidthLabel = (UILabel *)[finishingCopyWidthLabel viewWithTag:1];
fCopyWidthLabel.text = [prefsDictionary objectForKey:@"QuickWidthOne"];

最佳答案

根据你的问题更新,而不是这个 UILabel *fCopyWidthLabel = (UILabel *)[finishingCopyWidthLabel viewWithTag:1]; 试试这个

UILabel *fCopyWidthLabel = (UILabel *)[quickSelectionBar viewWithTag:1];

关于ios - 使用标记符号 objective-c 将文本分配给 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21549286/

相关文章:

ios - 如何将 UIImage 序列化为 JSON?

objective-c - 测量 CGFont 中最大字符的尺寸

javascript - 如何在 iPhone UIWebView 中使用 JavaScript 从 html 中删除标签

css - HTML H1,2,3,4,5,6 标题标签 - 仍然使用它们

ios - 通过保存 html 页面使加载 UIWebView 更快

ios - FFmpeg 的音频替代品 - Core Audio IOS

iPhone iOS 5 核心数据图像

objective-c - NSUserDefault 和开关

python - 生菜场景可以有多个标签吗?

iOS - 使用 AutoLayout 构建 UI 时,在界面构建中模拟指标下应该使用什么尺寸