Search code examples
iosobjective-csdk

how to control multiple buttons in one time?


i am a beginner ios developer and i am making TIC TAC TOE

i want to make an array to control all the buttons i one time instead of writing alot of code

so how can i link all 9 buttons in one array ?

instead of writing

button1 , button2 , button 3 ,button4 >> button [x]

or some thing like this

pleeeeease i am beginner so accept my question if it is stupid and dont rate down

or tell me where is the answer and i'll delete my question

thaaanks for your helping : - )


Solution

  • Access UIButton by it's TAG.

    Give different TAG to each UIButton

    For example

    for (int i = 1; i <=9; i++) {
            
            UIButton *button =(UIButton *)[self.view viewWithTag:i];
            
        }