swift - How to loop through buttons -


i have 16 buttons named btn1, btn2 etc.. how can loop through , set value each button?

i have code:

  //set values on button         in 1..<17{              var mybutton = "btn" + string(i);             println(mybutton)             mybutton.settitle(string(number), forstate: uicontrolstate.normal)         }      } 

but doesn't work because software sees string...

how can solve issue?

you can create array of buttons:

let array = [btn1, btn2, btn3 ...]  in array.count {    //do     array[i].settitle(string(number), forstate: uicontrolstate.normal) } 

but if have lot of buttons in interface builder, better way create them programmatically.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -