views:

29

answers:

1

hi I wanted to display randomly selected images in a view. below is an example of code i am using to generate random numbers to be displayed in a lable. ( its around about way to code it and im aware there is a more concise approach to code this. im doing it this way for a particular reason that i wont go into now). i wish to replace the the code with in each case to have code that calls a image to be displayed in the view

NSString *title = nil; NSString *path = nil;

int Number = arc4random() % 12; switch(Number) { case 0: namel.text = @"1";

            break;
  case 1:
            namel.text = @"2";

    break;

case 2:
            namel.text = @"3";

            break;

case 3:
            namel.text = @"4";

            break;

case 4:
            namel.text = @"5";

            break;
case 5:
    namel.text = @"6";

    break;

case 6:
    namel.text = @"7";

    break;

case 7:
    namel.text = @"8";

    break;

case 8:
    namel.text = @"9";

    break;



case 9:
    namel.text = @"10";

    break;

case 10:
    namel.text = @"11";

    break;

case 11:
    namel.text = @"12";

    break;


                    break;
            default:
            break;
} } @end
+2  A: 

You have to use UIImageView. Then you need an array of image name. When you random a number, just look up the index in the array and then call imageView.image = [UIImage imagedName:[array objectAtIndex:randomIndex]];

vodkhang