Reputation: 5829
Ok so I'm adding a please wait
popup for the operation that takes longer than usual in my ios app.
I have a segue from my ViewController to TabController and when I invoke it like this:
self.performSegueWithIdentifier("openMainApp", sender: self)
everything works fine.
But when I surround it with:
let alert = UIAlertController(title: nil, message: "Please wait...", preferredStyle: .Alert)
alert.view.tintColor = UIColor.blackColor()
let loadingIndicator: UIActivityIndicatorView = UIActivityIndicatorView(frame: CGRectMake(10, 5, 50, 50)) as UIActivityIndicatorView
loadingIndicator.hidesWhenStopped = true
loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray
loadingIndicator.startAnimating();
alert.view.addSubview(loadingIndicator)
presentViewController(alert, animated: true, completion: nil)
self.performSegueWithIdentifier("openMainApp", sender: self)
dismissViewControllerAnimated(false, completion: nil)
then I'm getting a warning:
Warning: Attempt to present <app.TabController: 0x7ff6dc00bd40>
on <app.ViewController: 0x7ff6d9cf6600> which is already presenting
<UIAlertController: 0x7ff6d9d78530>
how can I skip this warning?
Upvotes: 0
Views: 273
Reputation: 5450
While the source for this warning is still a mystery to me, there is a way to skip the warning.
Give storyboard ID to your view controller, something like:
Replace
self.performSegueWithIdentifier("openMainApp", sender: self)
with
let viewController: UIViewController =
self.storyboard!.instantiateViewControllerWithIdentifier("MainScene")
self.presentViewController(viewController, animated: true, completion: nil)
Upvotes: 1
Reputation: 4281
Idan's answer may work, but I would recommend using something like MBProgressHud or SVProgressHud. It looks like swift doesn't like it when you perform a segue before dismissing the alert controller because it is it's own view controller. Here is how to implement MBProgressHud. Here is how to implement SVProgressHud. If you don't want to use CocoaPods, you just download the zip file and add the .m and .h file into your project.
Upvotes: 0