I\'ve created a UIAlertView that contains a UIActivityIndicator. Everything works great, but I\'d also like the UIAlertView to disappear after 5 seconds.
Ho
Create the alert object as a global variable.
You can use a NSTimer for this purpose.
var timer = NSTimer.scheduledTimerWithTimeInterval(5.0, target: self, selector: Selector("dismissAlert"), userInfo: nil, repeats: false)
func dismissAlert()
{
// Dismiss the alert from here
alertView.dismissWithClickedButtonIndex(0, animated: true)
}
NOTE:
Important: UIAlertView is deprecated in iOS 8. (Note that UIAlertViewDelegate is also deprecated.) To create and manage alerts in iOS 8 and later, instead use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert.
Reference : UIAlertView