Search code examples
ioscocoa-touchuibuttonuikitibaction

Pressing 2 IBAction Buttons at the same time - iOS


So I have a basic game I'm developing for iOS. There's a 2 player mode and it involves hitting buttons. Once the button is hit (or pressed) something happens in the game.

So, each player has half of the screen, with their own buttons inside of their half, that act independently.

Do I need to worry about if player 1 hits a button on the lower part of the screen at the exact moment player 2 hit's a button on the top part of the screen?

If I do, do I need to handle it like the answer in THIS QUESTION.

I figure the chances are extremely slim, but never-the-less should be handled.


Solution

  • You don't need to worry about them being tapped at the same time. Since your buttons are independent each one should have it's own action method that is called when tapped, and it's okay if those methods are called at the same time since they do their own thing.

    The reason the question you linked to is different is that they wanted to do special logic IF both buttons were tapped. Since you don't care whether they were tapped at the same time, you don't need to implement that code.