UITextField 内容转 NSString
我目前正在制作一个使用单个 UITextField 的应用程序,以获得应用程序功能所需的信息。
我尝试过 textField.text 属性,但由于某种原因该字符串为空。
这是我尝试过的:
NSString *contents = urlField.text;
NSString *stringFromTextField = [[NSString alloc]initWithFormat:@"%@", contents];
我做错了什么?如果答案附有代码片段,那将会非常有帮助。
I am currently making an app that uses a single UITextField gain necessary information for the app's functionality.
I have tried textField.text property,, but for some reason the string is empty.
Here's what I have tried:
NSString *contents = urlField.text;
NSString *stringFromTextField = [[NSString alloc]initWithFormat:@"%@", contents];
What am I doing wrong?? It would really help if answers were accompanied by code snippets.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果没有第二行,第一行应该可以正常工作。也许 urlField 插座没有连接到 NIB 中的实际 UI 控件?
The first line should work just fine without the second. Maybe the urlField outlet isn't hooked up to the actual UI control in the NIB?
text
成员分配给您的字符串即可。您确定正确设置/初始化了 urlField.text(它链接到 IB 中的控件还是手动执行)?
只是一件小事:您也可以使用
urlField.text
进行进一步处理,因为urlField.text
已经是NSString
text
member to your string.Are you sure you're setting/initializing the urlField.text properly (Is it linked to a Control in IB or are you doing it manually)?
Just a small thing: You can as well just use
urlField.text
for further processing becauseurlField.text
already is of typeNSString