如何设置字符串值等于UITextField?
我正在尝试让您在文本字段中输入一个数字,然后按一个按钮。字符串等于文本字段,标签等于字符串。问题是当我按下按钮时它崩溃了。我做错了什么?
来自 .h 文件:
@interface TextGameViewController : UIViewController
{
IBOutlet UITextField *input;
IBOutlet UILabel *line11;
NSString *l11;
}
-(IBAction)button;
来自 .m 文件:
-(IBAction)button
{
[input resignFirstResponder];
l11 = ([input.text stringValue]);
line11.text = [[NSString alloc] initWithFormat:@"%2.f", l11];
}
I'm trying to make it so you type in a number in a text field, then you press a button. A string is then equal to the text field and a label is then equal to the string. The problem is it crashes when i pres the button. What am I doing wrong?
from the .h file:
@interface TextGameViewController : UIViewController
{
IBOutlet UITextField *input;
IBOutlet UILabel *line11;
NSString *l11;
}
-(IBAction)button;
from the .m file:
-(IBAction)button
{
[input resignFirstResponder];
l11 = ([input.text stringValue]);
line11.text = [[NSString alloc] initWithFormat:@"%2.f", l11];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
l11 已经是一个
NSString
,将此行代码更改为:To
l11 is already a
NSString
, change this line of code from:To