Fabian Fabian - 7 months ago 46
iOS Question

Display UIAlertController as long a function lasts

I have a update function that is called when the refresh button in my app is pressed.
In the update function I call some other functions that fetch the new data and then set all textfields with the new values. As long as the function is not completely performed, I would like to display an UIAlertController that shows the user an Alert Popup.
The code for the UIAlertController looks like this:

@IBAction func btnReloadDataTapped(_ sender: AnyObject) {
let refreshAlert = UIAlertController(title: "Refreshing Data", message: "This might take a few moments.", preferredStyle: UIAlertControllerStyle.alert)

present(refreshAlert, animated: true, completion: nil)

Is there a clean way to perform this task with Swift 3?


When all your tasks are finish, in your UIVIewController just call

self.dismiss(animated: true, completion: nil)