当尝试从 UITextField 获取文本值时,值为 null/空/垃圾
我有一系列文本字段,用户将在值中输入(一个是字符串,其他是数字)。当我尝试从以下位置获取文本时:
NSString *strCal = txtfieldCal.text;
NSLog(@"cal entered: %a", strCal);
Returns:
calories Entered: -0x1.fd55804e2e26p+0
我在 IB 中正确引用了插座。
我不知道这是否重要,但我可以在视图加载上填充文本字段,但之后无法获取值。
I have a series of textfields the user will enter in values (one is a string the others numeric). When I try to get the text from:
NSString *strCal = txtfieldCal.text;
NSLog(@"cal entered: %a", strCal);
Returns:
calories Entered: -0x1.fd55804e2e26p+0
I have the outlets referenced correctly in IB.
I don't know if this matters or not, but I can populate the textfields on viewload, but I cannot get the value afterwards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用 %@ 将字符串放入 NSLog 中。 %a 可能显示其他内容, - 它看起来像终端中手册页中的数字(类型 man printf)
NSLog(@"cal Entered: %@", strCal);
只是觉得你可能想要一个号码。好吧,你得到一个字符串 - 它是一个文本字段。要获取数字,您可以调用类似
NSLog(@"cal Entered: %f", [strCal doubleValue]);的函数
You need to use %@ to put strings into NSLog. %a likely shows something else, - it looks like a number from the man page in terminal (type man printf)
NSLog(@"cal entered: %@", strCal);
Just thought that you may well WANT a number. Well you get a string -its a text field. To get a number, you call something like
NSLog(@"cal entered: %f", [strCal doubleValue]);