Objective-C,我如何获得UITextField的值?

时间:2023-02-03 15:05:34

How can i get the value of a UITextField? Some sample code to attach it to an NSString would be fab!

如何获得UITextField的值?将它附加到NSString的一些示例代码将是fab!

3 个解决方案

#1


10  

The UITextField has to be connected to your file through Interface Builder, and declared as an IBOutlet in your header file:

UITextField必须通过Interface Builder连接到您的文件,并在头文件中声明为IBOutlet:

IBOutlet UITextField *textField;

Then you'd access it in your methods as:

然后你可以在你的方法中访问它:

NSString *enteredText = [textField text]; // Or textField.text

#2


4  

NSString *tf_text = [ yourTextField text ];

#3


0  

If in doubt always look at the documentation it'll give you the answer faster than asking on here!

如果有疑问,请始终查看文档,它会比在这里询问更快地给你答案!

In this case: UITextField and for future reference: iPhone class documentation

在这种情况下:UITextField并供将来参考:iPhone类文档

#1


10  

The UITextField has to be connected to your file through Interface Builder, and declared as an IBOutlet in your header file:

UITextField必须通过Interface Builder连接到您的文件,并在头文件中声明为IBOutlet:

IBOutlet UITextField *textField;

Then you'd access it in your methods as:

然后你可以在你的方法中访问它:

NSString *enteredText = [textField text]; // Or textField.text

#2


4  

NSString *tf_text = [ yourTextField text ];

#3


0  

If in doubt always look at the documentation it'll give you the answer faster than asking on here!

如果有疑问,请始终查看文档,它会比在这里询问更快地给你答案!

In this case: UITextField and for future reference: iPhone class documentation

在这种情况下:UITextField并供将来参考:iPhone类文档