如何在XCode中获取文本字段的文本 [英] How to get a Text Field's text in XCode
问题描述
我使用界面构建器创建了一个文本字段。如何在其他地方使用其文本?
I made a Text Field with interface builder. How can I get its text to use somewhere else?
是否有类似的内容:
string text = myTextField.Text;
如果是这样,我如何命名我的文本字段?
If so, how can I name my text field?
推荐答案
所以你要做的第一件事就是在与xib文件关联的视图控制器文件的.h文件中创建一个属性,如下所示:
So the first thing you want to do is create a property in the .h file of the view controller files associated with your xib file like so:
@property (strong, nonatomic) IBOutlet UILabel *aLabel;
接下来在.m文件中你需要合成它:
Next in the .m file you need to synthesize it like so:
@synthesize aLabel;
在您的实施标签中。
现在在界面构建器控件中单击Xcode 4.3屏幕左侧的文件所有者,按住并拖动标签然后松开。然后在弹出窗口中选择您创建的属性的名称。现在,在视图控制器的viewDidLoad方法中,您可以获得如下值:
Now in interface builder control click where it says "File's Owner" on the left side of the screen in Xcode 4.3 hold down and drag over the label and let go. Then in the popup select the name of the property you created. Now in the viewDidLoad method of your view controller you can get at your value like so:
self.alabel.text
这篇关于如何在XCode中获取文本字段的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!