简体   繁体   English

如何从 ViewController 到 NSObject 获取 UITextField 字符串

[英]How to get UITextField String from ViewController to NSObject

Hi i am trying to pass the value from my UITextfield that is declared and being used in my ViewController over to an NSObject I have created that needs the value in it to perform an operation.嗨,我正在尝试将我的 UITextfield 中声明并在我的 ViewController 中使用的值传递给我创建的需要其中的值来执行操作的 NSObject。 I'm just not sure what I have to do, I have tried this我只是不确定我必须做什么,我已经尝试过了

I have declared the UITextField in my ViewControllers header file and created an IBOutlet for it.我已经在我的 ViewControllers header 文件中声明了 UITextField 并为它创建了一个 IBOutlet。

Then I have #imported this into my NSObject and tried to call it like this NSString *tempTextField = regTextField.text;然后我将它#imported到我的NSObject中并尝试像这样调用它 NSString *tempTextField = regTextField.text;

and its getting a error 'regTextField not defined'.并且它得到一个错误'regTextField not defined'。

If regTextField is defined in your ViewController subclass, then you probably want to set the text field in your NSObject from your view controller.如果在您的 ViewController 子类中定义了 regTextField,那么您可能希望从您的视图 controller 中设置 NSObject 中的文本字段。 I would import your NSObject into the view controller and then have an NSString property in your NSObject that you can set from the viewController.我会将您的 NSObject 导入到视图 controller 中,然后在您的 NSObject 中有一个可以从 viewController 设置的 NSString 属性。

myClass.fieldIWantToSet = self.regTextField.text;

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM