nickt
nickt

Reputation: 21

ios objective c help with array please!

im new to programming and im trying to make my first iphone app. basically what my app needs to do is draw a random image from an array and output it to a UIImageView in a view. it should be really simple but i cant find anywhere on the internet how to output the array to the uiimage

theArray = [[NSArray alloc] initWithObjects:@"one.png",@"two.png",@"three.png",nil];

heres a basic code of the images. any help would be greatly appreciated!!

also if you could explain any other details i might need.

Upvotes: 2

Views: 1014

Answers (1)

Saurabh
Saurabh

Reputation: 22873

find a random array index using -

int randomArrIndex = arc4random() % [arr count];

then you can fetch image name from array with this index

UIImageView *imgView = [[UIImageView alloc] initWithImage:[arr objectAtIndex:randomArrIndex]];

Upvotes: 3

Related Questions