Ich kann den Code nicht erkennen, wenn die Textfelder HourGoal und MinuteGoal leer sind. Sie werden nie mit einem Nullwert oder leer angezeigt, was dazu führt, dass das Programm abstürzt, wenn ich versuche, die Werte auszupacken.erkennt Textfeld nicht als leer
import UIKit
class ReadingGoal: UIViewController {
@IBOutlet weak var HourGoal: UITextField!
@IBOutlet weak var MinuteGoal: UITextField!
@IBOutlet weak var NextButton: UIButton!
var mingoal = Int()
var hrgoal = Int()
var secondstoread:Int = 0
var initialtime:Int = Int()
@IBAction func HourEditingDidChange(_ sender: Any) {
NextButton.isEnabled = true
}
@IBAction func MinuteEditingDidChange(_ sender: Any) {
NextButton.isEnabled = true
}
func disable() {
NextButton.isEnabled = false
}
@IBAction func NextButtonIsPressed(_ sender: Any) {
print("GERALDINE IS AWESOME!!!!!")
// ERROR
if HourGoal.text?.isEmpty == false || MinuteGoal.text?.isEmpty == false {
if HourGoal.text != nil && HourGoal.text?.isEmpty == false{
// self.hrgoal = Int(HourGoal.text!)!
print("hr Value exists")
print("\(HourGoal.text!)")
}
else {
NextButton.isEnabled = false
}
if MinuteGoal.text != nil && MinuteGoal.text?.isEmpty == false{
// self.mingoal = Int(MinuteGoal.text!)!
print("min value exists")
print("\(MinuteGoal.text!)")
}
else {
NextButton.isEnabled = false
}
print("in ")
// secondstoread = ((mingoal + (hrgoal*60))*60)
secondstoread = 10
if secondstoread > 0 {
performSegue(withIdentifier: "Mr.Friar-DavisIsAGiantBallOfFloof", sender: self)
}
else {
NextButton.isEnabled = false
}
//function saves text field info to core data
}
}
//for the specific segue 'toBookInfo', certain information is passed through the segue
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
//making sure we are using correct segue
if segue.identifier == "Mr.Friar-DavisIsAGiantBallOfFloof" {
//selecting the destination controller
let detailVC: TimerController = segue.destination as! TimerController
//sending properties to destination view controller
detailVC.seconds = secondstoread
}
else {
// Error sender is not a cell or cell is not in collectionView.
}
}
override func viewDidLoad() {
super.viewDidLoad()
initialtime = secondstoread
}
}