I'm assuming there is an easy way to do this, but I think that it will add a lot to my app visually if I can get it to work. Behind 开发者_开发问答my detail view controller (it's a drill-down app), I load an image, similar to the default blue ribbons, except customized. I would like to add three or four images that are randomly put on screen (as in, there are 30 items on my list, and if a user were to go through each, I want to make them all visually stimulating). Obviously, you create an image view, add my images to the project. I'm assuming that my solution would lie somewhere in my DetailViewController.m's viewDidLoad method. How do I tell the image view to randomly display one of three images? Do I create an Array of images and then tell it to pick one in a particular way?
Many thanks in advance.
NSArray *images = [[NSArray alloc] initWithObjects:@"image1.png", @"image2.png" @"etc.png", nil];
int count = [images count];
int randNum = arc4random() % count;
myImageView.image = [UIImage imageNamed:[images objectAtIndex:randNum]];
That should do it!
精彩评论