【问题标题】:How to access UIlabel, UIbutton, UIimageview or UItextfield using a string value - iOS如何使用字符串值访问 UIlabel、UIbutton、UIimageview 或 UItextfield - iOS
【发布时间】:2012-03-22 20:14:09
【问题描述】:

我正在开发一个应用程序,它的视图包含 UILabelUIButtonUIImageViewUITextField。我想以编程方式创建 UIlabel、UIbutton、UIImageView 或 UItextfield,其中包含我将从网络服务接收。

以编程方式创建 UIlabel、UIbutton、UIImageViewUITextField 后,我该如何访问?

我将有很多对象,我的想法是为每个对象设置一个名称/ID(我不知道是否可能)。

然后我会有一个包含对象名称的字符串的数组。

NSString *textFieldName = @"nameX";

现在有了对象的名称,我该如何访问,例如获取值?

【问题讨论】:

    标签: ios uibutton uitextfield uilabel


    【解决方案1】:

    你需要的是使用一个标签,你把一个标签放到视图中,然后你像这样检索:

     //first you put a tag in your fresh created view, for ex a button
     #define TAG_BUTTON 123
    
     myButton.tag = TAG_BUTTON;
    
    
    
    //And you retrieve like this:
    
    UIButton *myButtonRetrieved = [self.view viewWithTag:TAG_BUTTON]
    

    【讨论】:

    • 谢谢,我从未见过 tag 属性。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多