I have an unwind segue which takes a few seconds to complete while it saves images to disk. I want to display an activity indicator until the view is dismissed but the view doesn't update.
This is my function, which is called from the view controller before it's dismissed:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "saveRecord" {
print("indicator")
let indicator = UIActivityIndicatorView()
indicator.frame = self.view.frame
indicator.activityIndicatorViewStyle = .whiteLarge
indicator.color = UIColor.blue
indicator.hidesWhenStopped = true
indicator.startAnimating()
self.view.addSubview(indicator)
self.view.layoutSubviews()
print("laid out subviews")
}
}
The two print statements execute, and the debugger shows that the indicator has been added to the main view as a subview, but it doesn't appear on screen. Am I missing something?
I know the position of the indicator isn't a problem because running the same code in viewDidLoad correctly shows it in the middle of the screen.
UPDATE
I've recreated the segue functions using a delegate and it's saving everything correctly, but the problem remains. Still no activity indicator.
@IBAction func saveRecord(_ sender: Any) {
print("indicator")
let indicator = UIActivityIndicatorView()
indicator.frame = self.view.frame
indicator.activityIndicatorViewStyle = .whiteLarge
indicator.color = UIColor.blue
indicator.hidesWhenStopped = true
indicator.startAnimating()
self.view.addSubview(indicator)
self.view.layoutSubviews()
print("laid out subviews")
saveImages()
print("saved images")
self.delegate?.saveRecord(name: name!, category: category)
print("saved record")
self.navigationController?.popViewController(animated: true)
}
UPDATE 2
I'm really confused now! This starts the indicator:
@IBAction func saveRecord(_ sender: Any) {
print("indicator")
indicator.startAnimating()
//saveImages()
//print("images saved")
//performSegue(withIdentifier: "saveRecord", sender: self)
}
but this doesn't:
@IBAction func saveRecord(_ sender: Any) {
print("indicator")
indicator.startAnimating()
saveImages()
print("images saved")
performSegue(withIdentifier: "saveRecord", sender: self)
}
performSegue
some where in your code? – Ahmad F