5

I have a group of 4 buttons and I want the currently selected button to disable the other 3(while performing an alpha fade animation)

What would be the best practise for handling this in Swift?

TylerH
  • 20,799
  • 66
  • 75
  • 101
  • possible duplicate of [Best radio-button implementation for IOS](http://stackoverflow.com/questions/4847296/best-radio-button-implementation-for-ios) – Matt Gibson Feb 25 '15 at 07:57
  • 1
    Fair enough. Im not looking for code however. Just the logic. I know how I could accomplish it but it seemed a bit messy to me. I'm pretty new to coding so I was wondering if there was a 'best way' it should be handled. –  Feb 25 '15 at 07:59

2 Answers2

8
  1. Connect all of them to an Outlet Collection (when dragging the first one to the VC select "Outlet Collection", then one by one drag the rest to the same property - which will be an array). Outlet Collection
  2. Connect all of them to the same action (same as 1 but choose "Action", then drag all pf them to that action), and keep the "sender" argument. Action
  3. In the action, your sender will be equal to one of the connected buttons in the collection. Run a for-in loop on the Outlet Collection array, anything that's not the sender - disable. If it's the sender - enable...
Aviel Gross
  • 9,770
  • 3
  • 52
  • 62
1

My personal opinion, connect them all to an Outlet Collection (Array) and link them all to the same function with different tags. And loop on them all each time you click on a button to decide which to disable and which to enable.

Ashraf Tawfeeq
  • 3,036
  • 1
  • 20
  • 34