当尝试从 UITextField 获取文本值时,值为 null/空/垃圾

发布于 2024-12-19 21:58:07 字数 307 浏览 0 评论 0原文

我有一系列文本字段,用户将在值中输入(一个是字符串,其他是数字)。当我尝试从以下位置获取文本时:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

聆听风音 2024-12-26 21:58:07

您需要使用 %@ 将字符串放入 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]);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文