3 个 UITextField 的总和? [英] Sum of 3 UITextField?
本文介绍了3 个 UITextField 的总和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么结果是 123 而不是 6 ?
Why the result is 123 and not 6 ?
谁能详细解释一下?
推荐答案
您正在标签文本中将文本 (String
) 值相互添加.你应该这样做:
You are adding the text (String
) values to each other in the label text. You should do this instead:
guard let num1 = Int(textField1.text),
let num2 = Int(textField2.text),
let num3 = Int(textField3.text) else {
return
}
let sum = num1 + num2 + num3
label.text = str+sum
这篇关于3 个 UITextField 的总和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文