with the shouldPerforSegue()
func I am able to check some fields before seguing, however, I need it to continue with the segue even if the fields were bad at the time of triggering the segue.
Right now, when the user clicks on a button that triggers a segue, I am checking to see if the images are already uploaded to the server. I display a progress bar along with an alert to indicate the % left. However, right now after the image is uploaded to the server with the progress bar indicating 100%. I still have to manually click "ok" and re-click the seguing button. I am trying to see if there was a way to bypass this hindrance, by just continuing with the segue.
I have tried programmatically triggering the segue button after the image is uploaded, but it does not work as intended.
UIApplication.shared.sendAction(self.saveButton.action!, to: self.saveButton.target, from: nil, for: nil)
The function I have that checks for validation:
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
if ((sender as? UIBarButtonItem) != nil) && uploadingImagesToFirebase {
// Create the alert controller
let alertController = UIAlertController(title: "Uploading Images...", message: "", preferredStyle: .alert)
// Create an ok button
let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.default) { (result : UIAlertAction) -> Void in
print("OK")
}
alertController.addAction(okAction)
self.present(alertController, animated: true, completion: {
// Add your progressbar after alert is shown (and measured)
let rect = CGRect(x: alertController.view.frame.width * 0.10, y: alertController.view.frame.height / 2, width: alertController.view.frame.width * 0.80, height: 100)
self.progressView = UIProgressView(frame: rect)
alertController.view.addSubview(self.progressView!)
})
return false
}
return true
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// If user clicks on a job cell
if segue.identifier == "showJobDetails" {
...
}
else if addJobButton == sender as? UIButton {
print("Adding a new job from customer view")
...
}
// If save button was choice selected by user
else if segue.identifier == "identifier {
customer.firstName = firstNameTextField.text
customer.middleName = middleNameTextField.text
customer.lastName = lastNameTextField.text
customer.address = addressTextField.text
customer.email = emailTextField.text
customer.phone = phoneTextField.text
customer.jobs = customerJobs
updateCustomerValuesInFirebase()
updateJobValuesInFirebase()
}
}