【发布时间】:2017-10-02 00:20:27
【问题描述】:
我有一段代码允许用户输入他们的姓名并在按下按钮时前进到下一个屏幕。如果未输入任何值,程序不应允许用户继续前进。该程序确实检测到何时没有输入名称并且不会移动到下一个屏幕,但会以 NSException 类型的未捕获异常终止。我想允许用户继续输入值(名称),直到实际输入名称(即名称值不留空)。有什么办法可以做到这一点。 While/for 循环似乎不起作用。
@IBAction func NameEditingDidChange(_ sender: Any) {
NextButton.isEnabled = true
}
// Once button is pressed
@IBAction func NextButtonPressed(_ sender: Any) {
// Gets user's name from textfield
print("12345abcde")
self.name = NameInput.text!
// If textfield is not empty, moves to next storyboard
if name.characters.count != 0 {
print("in ")
performSegue(withIdentifier: "fistBump", sender: nil)
}
else {
// Prints this line and terminates
print("text field is empty")
}
【问题讨论】:
-
我认为需要
self.inself.name.characters.count。
标签: swift uitextfield segue action