1

我有 20 多个标签需要在运行时更新,我想知道是否可以在无需为所有标签声明属性和插座的情况下访问它们。我尝试为每个标签分配一个唯一的标签,并通过我的视图控制器中的视图访问它们,如下所示:

 self.view.myLabel1.text = @"Some text";

但它没有用。有没有办法做到这一点?

谢谢

4

2 回答 2

3

标签方法是正确的方法,但您必须以不同的方式访问标签。假设self.view是标签的父视图并且所有标签都有一个唯一的标签(整数),你可以像这样得到它们:

UILabel *label = (UILabel *)[self.view viewWithTag:1];
于 2011-02-02T14:38:16.067 回答
0

As far as i know Xcode does not know nothing about your xib UIElements if you don't declare them. I had similar dilemma long time ago, and since then, when i have a large number of objects from the same kind i prefer to make them reusable by creating them programmatically.

good luck

于 2011-01-31T12:57:34.380 回答