How can I call func checkField when nextButton is tapped? If no field is empty in ManagedTableEleventhViewController, I\'d like to segue to TwelvethViewController.
I hav
Thanks to this answer I have obtained the desired result.
class EleventhViewController: UIViewController {
@IBAction func nextButton(_ sender: Any) {
var managed: ManagedTable? {
return self.childViewControllers.last as! ManagedTable?
//if there is no empty field after checkField(sender:_) is called,
// segue to TwelvethViewController
managed?.checkField(sender: self)
}
}
}
class ManagedTableEleventhViewController {
// holds a true value if textField contains a value
var hasText:Bool!
//holds a true/false value for each textField after iterating through them
//with a for loop
var textValues = [Bool]()
//When nextButton is touched in EleventhViewController, call this method
func checkField(sender:EleventhViewController) {
for cell in self.tableView.visibleCells{
for sub in cell.contentView.subviews{
if sub is UITextField{
let textF = sub as? UITextField
//if textField is empty, make its border red,else clear
if textF?.text == "" {
self.hasText = false
self.textValues.append(self.hasText)
textF?.layer.cornerRadius = 8.0
textF?.layer.masksToBounds = true
textF?.layer.borderColor = UIColor.red.cgColor
textF?.layer.borderWidth = 1.0
} else {
self.hasText = true
self.textValues.append(self.hasText)
}
}// end of if sub is UITextField
}//end of for sub in cell.contentView
} //end of for cell in tableView
//if no field is empty perform segue to TwelvethViewController,
//otherwise reset textValues array
if !self.textValues.contains(false){
sender.performSegue(withIdentifier: "eleventhToTwelveth", sender: sender)
}
self.textValues.removeAll()
} //end of checkField(sender:_)
}//end of class