Create a for loop to add 39 buttons to an array

前端 未结 5 743
情书的邮戳
情书的邮戳 2021-01-02 11:07

I have 39 different UIButton variables in my .h file, but I would like to add each of them to an array without having to type out the same thing 39 times.

Is there a

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-02 11:19

    Key Value programming is your friend

    Basically you can loop around and create your buttons, and as long as you have properties defined for your buttons you can.

    [self setObject:newButton forKey@"button1"];
    

    where button1 is the same string as your variable name.

提交回复
热议问题