How do I get the text from UITextField into an NSString?

跟風遠走 提交于 2019-12-04 17:25:43

问题


I've tried various methods, which all give me warnings. Such as userName = [NSString stringWithFormat:@"%@", [yournamefield stringValue]]; which just gives me a warning of

'UITextField' may not respond to '-stringValue'

How do i do this?


回答1:


Get the text inside the text field using the text property

NSString *name = yourNameField.text;



回答2:


Use the text property of UITextField:

NSString *userName = yourNameField.text;



回答3:


How about:

userName = [NSString stringWithFormat:@"%@", yournamefield.text];



回答4:


Two ways. It is a property and any property value can be accessed like this -

  • yournamefield.text
  • [yournamefield text]


来源:https://stackoverflow.com/questions/4660200/how-do-i-get-the-text-from-uitextfield-into-an-nsstring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!