将 UITextField 值转换为 NSString
我有一个应用程序的一部分用于将单位从英尺和英寸转换为厘米。
我通过两个 UITextField 输入接受用户的英尺和英寸,效果很好。然后我想对输入的值执行计算并将结果显示在下面的标签中。点击“转换”按钮时我用于计算的代码如下;
-(IBAction)heighConvertButtonAction:(id)sender {
NSString *feetCM = heightFeetField.text;
NSString *inchesCM = heightInchesField.text;
float fFeet = 30.48 * [feetCM integerValue];
float fInches = 2.54 * [inchesCM integerValue];
float fFeetInches = fFeet + fInches;
fFeetInchesResult = [NSString stringWithFormat:@"%", fFeetInches];
heightCMLabel.text = fFeetInchesResult;
它
的工作原理是,它不会产生任何错误,但是,当触摸转换按钮时,它不会执行任何操作。我希望它能用结果填充“heightCMLabel”标签。
任何帮助将不胜感激。
谢谢
I am having a section of an application used for converting units from feet and inches to centimetres.
I accept the feet and inches from the user through two UITextField inputs which works fine. I then want to perform a calculation on the inputted values and display the result in a Label underneath. The code I am using for the calc when the 'convert' button is tapped is as follows;
-(IBAction)heighConvertButtonAction:(id)sender {
NSString *feetCM = heightFeetField.text;
NSString *inchesCM = heightInchesField.text;
float fFeet = 30.48 * [feetCM integerValue];
float fInches = 2.54 * [inchesCM integerValue];
float fFeetInches = fFeet + fInches;
fFeetInchesResult = [NSString stringWithFormat:@"%", fFeetInches];
heightCMLabel.text = fFeetInchesResult;
}
It works in the sense that it doesnt produce any errors, however, when the convert button is touched it doesn't do anything. I was hoping it would populate the 'heightCMLabel' label with the result.
Any help would be appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定这是否只是发布代码时的错误,但这不是有效的字符串格式化程序。
尝试:
Not sure if it was just an error when posting your code, but that's not a valid string formatter.
Try: