How can I do this..???? Help please...

Discussion in 'iPhone/iPad Programming' started by bytezone, May 6, 2009.

  1. macrumors member

    Joined:
    Apr 20, 2009
    #1
    Can anyone tell me how I can do this..

    I need to create 10+ buttons dynamicaly and link the image of button to randomly selected images from the list. Every time the application is refreshed, I would like to reasign the images randomly to each button, so that no button gets same image on every refresh. The images in the list is 6 in total but buttons are more than 10+. Also each button needs to be linked to a single action.

    Can anyone give me suggestions or direct me to resource which could help me implement this...??

    Thanks
     
  2. macrumors regular

    Joined:
    Apr 9, 2009
    #2
    could you please be more specific?

    1) what do you mean by "each time the application is refreshed"?

    2) "so that no button gets same image on every refresh" ... do you mean the same as before? because if you have 6 images but 10+ buttons, some buttons MUST have the same images

    in any case this should be pretty simple. you create a for-loop, and for every loop you create a button. if you need to store the buttons you can do so in an array.
    after that, you get a random entry of the array your images are in (google "random numbers in c" to find out how to create a random number, then you take that random number as the index of the image in the array. you, of course, have to make sure the random number doesn't exceed the number of items in your array) and use that image.
     
  3. thread starter macrumors member

    Joined:
    Apr 20, 2009
    #3
    Thanks for the response.

    Thanks will try it out...!!!
     

Share This Page