0

I am making a simple game that presents an alert controller to notify the player when they have won or lost a battle. Sometimes there are simultaneous attacks such that both combatants lose health at the same time and are slain. The alert controllers are each in separate if statements, but when both are called I was hoping they would both be called sequentially and after dismissing the first one the second one would be presented, but instead I get the following error message:

Warning: Attempt to present on which is already presenting

I looked for a solution and saw recommendations for having the first alert controller call the second, but I didn't want to use the solution since it is rare that both alert controllers are called at the same time.

Is there a better solution for handling this or would my best bet be to reconfigure the code so that one alert controller calls the other or to stop using alert controllers?

Dominick
  • 164
  • 2
  • 4
  • 13
  • 1
    You have an alert go off for every interaction between combatants or for the overall battle? Further, why are you using alert controllers? If you are only trying to use a prompt, then why not create your own UIView that can not only present the user with a dialogue, but be updated if a second loss occurs while it is present? – Jay Jul 04 '17 at 22:01
  • see [Loop over multiple UIAlertController's](https://stackoverflow.com/questions/28997342/loop-over-multiple-uialertcontrollers) <-The link also suggest to use a tableView if you want to present multiple alerts at the same time). As another way: I'm not so sure if this is a non-breakable solution but using notifcationCenter you could direct ALL alerts to [topViewController](https://stackoverflow.com/questions/30570861/get-the-top-viewcontroller-in-ios-swift) and from there dismiss the current alert and present a newer one OR subclass alerts with a priority attribute and manage them accordingly – mfaani Jul 05 '17 at 00:27
  • Thank you all for your input. I think Jay is right, the best/simplest solution for me is going to be to abandon the alert controller method and use a different UIView for presenting the data. – Dominick Jul 05 '17 at 20:04

0 Answers0