我有一个包含 2 个 switch 语句的按钮。
buttonPressed() {
switch 1
switch 2
}
开关 1 检查错误。如果未发现错误,则执行 Switch 2。这部分效果很好。
问题是,当发现错误时,在第二次按下按钮时,开关 1 被跳过。
如何使按钮在每次按下时始终从头开始执行?
就好像它在开关的末尾创建了一个断点,第二次按下从该断点继续。
这是 switch1 的摘录:
case 1:
let oneLength = countElements(textOne.text)
if oneLength <= 1 {
self.shouldSave = false
showAlertWithText(message: "First checklist item must have a value")
} else if oneLength >= 141 {
self.shouldSave = false
showAlertWithText(message: "First checklist item exceeds the 140 character limit")
} else {
newChecklistOne["goalID"] = self.dependantGoalID
newChecklistOne["itemDescription"] = textOne.text
newChecklistOne["isComplete"] = false
}
开关 2 示例:
if self.shouldSave == true {
while self.saveVarTwo <= self.z {
switch self.saveVarTwo {
case 1: newChecklistOne.saveInBackground()
这是 showAlertWithText 函数:
func showAlertWithText (header : String = "Ermahgerd!!!", message : String) {
var alert = UIAlertController(title: header, message: message, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
那么,如何让按钮在每次单击按钮时从第 1 行开始执行代码?
最佳答案
因此,我有一个“saveVar”作为开关 1 的开关催化剂。它会迭代到条目数,但我从不在发生错误时重置它。因此,当按下按钮时,开关会在最大情况下启动。
关于swift - 如何使按钮重置为默认状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29620264/