作者:再体验初体验g_154 | 来源:互联网 | 2023-05-18 08:26
我在执行代码的键盘上的返回键有问题.我在过去尝试过以下代码完美无缺:
func textFieldShouldReturn(textField: UITextField) -> Bool{
textField.resignFirstResponder()
valueOfLetter()
return true;
}
但是,由于某种原因,该线路上存在错误valueOfLetter
.
如果有必要,这是整个文件:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBOutlet weak var strWordValue: UILabel!
@IBOutlet weak var strInputField: UITextField!
func textFieldShouldReturn(textField: UITextField) -> Bool{
textField.resignFirstResponder()
valueOfLetter()
return true;
}
var TextField: UITextField!
func valueOfLetter(inputLetter: String) -> Int {
let alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
for (index, letter) in alphabet {
if letter = inputLetter.lowercaseString {
return index + 1
for character in word {
score += valueOfLetter(character)
}
}
}
return 0
}
}
错误是:"在调用参数#1中缺少参数
该行的另一个错误是for (index, letter) in alphabet
:'String'不能转换为'([String,String])'
我不确定这些错误是什么意思或如何解决它们.
任何意见或建议将不胜感激.
提前致谢.
1> kellanburket..:
您的方法valueOfLetter
需要一个参数,您需要使用参数调用它,否则它将无法工作.例如:
valueOfLetter("x")
您的第二个错误正在发生,因为您使用的语法结构用于迭代带有数组的字典.使用内置enumerate
函数迭代具有索引值的数组:
for (index, letter) in enumerate(alphabet) {
if letter = inputLetter.lowercaseString {
return index + 1
for character in word {
score += valueOfLetter(character)
}
}
}