-1

这是我的代码:

-(void)RandomButtonImage {

    NSMutableArray *images = [NSMutableArray arrayWithObjects:@"Character_1_1.png",@"Character_1_2.png",@"Character_2_1.png",@"Character_2_2.png" nil];

    NSArray *Buttons = [NSArray arrayWithObjects:AnsButton1,AnsButton2,AnsButton3,AnsButton4, nil];

    for (UIButton *btn in Buttons) {
        int randomIndex = random() % images.count;
        UIImage *img = [images objectAtIndex:randomIndex];
        [btn setImage:img forState:UIControlStateNormal];
        [images removeObjectsAtIndexes:randomIndex];
    }
}

我尝试查看其他帖子,但是我的编码完全相同。

4

2 回答 2

3

images是 的数组NSString,而不是 的数组UIImage

尝试这个:

UIImage *img = [UIImage imageNamed:[images objectAtIndex:randomIndex]];
于 2013-05-20T17:54:01.463 回答
0

removeObjectsAtIndexes想要一个NSIndexSet,而不是一个整数:

要么使用[images removeObjectAtIndex:randomIndex];

或者[images removeObjectsAtIndexes:[NSIndexSet indexSetWithIndex:randomIndex]];

于 2013-05-20T17:56:20.127 回答