1
我能夠從數組中顯示8個圖像中的5個圖像。但我得到這個代碼重複的圖像:如何顯示圖像,而無需在objective-c中重複數組?
int index1 = arc4random()%8;
UIImage *card1=[UIImage imageNamed:[imageArray objectAtIndex:index1]];
[b1 setImage:card1 forState:UIControlStateNormal];
int index2 = arc4random()%8;
UIImage *card2=[UIImage imageNamed:[imageArray objectAtIndex:index2]];
[b2 setImage:card2 forState:UIControlStateNormal];
int index3 = arc4random()%8;
UIImage *card3=[UIImage imageNamed:[imageArray objectAtIndex:index3]];
[b3 setImage:card3 forState:UIControlStateNormal];
int index4 = arc4random()%8;
UIImage *card4=[UIImage imageNamed:[imageArray objectAtIndex:index4]];
[b4 setImage:card4 forState:UIControlStateNormal];
int index5 = arc4random()%8;
UIImage *card5=[UIImage imageNamed:[imageArray objectAtIndex:index5]];
[b5 setImage:card5 forState:UIControlStateNormal];
檢查中問題的功能:HTTP:// stackoverflow.com/questions/9798647/objective-c-uibutton-image-with-nsarray-in-a-random-order – Sarah 2012-03-22 06:54:40