UIImageView内存分配

时间:2013-02-20 20:38:47

标签: objective-c memory uiimageview uiimage

在我的一个类中,当视图加载时,随机图像(来自50个图像的列表)被分配给所有24个UIImageViews(6行,4列)。但是,当视图加载大约三次时,应用程序会因内存问题而崩溃。我很确定这是一个分配问题,但我真的不知道从哪里开始...

这就是我去做UIImages的方式:

greenApple= [UIImage imageNamed: @"greenApple.png"];
redApple = [UIImage imageNamed: @"redApple.png"];
burger = [UIImage imageNamed: @"cheeseBurger.png"];
fries = [UIImage imageNamed:@"fries.png"];
blackCookie = [UIImage imageNamed:@"blackCookie.png"];
whiteCookie = [UIImage imageNamed:@"whiteCookie.png"];
pizza = [UIImage imageNamed:@"pizza.png"];
orange = [UIImage imageNamed:@"orange.png"];
plyers = [UIImage imageNamed:@"plyers1.png"];
scissors = [UIImage imageNamed:@"scissors1.png"];
watch = [UIImage imageNamed:@"watch.png"];
clippers = [UIImage imageNamed:@"clippers1.png"];
... etc

这就是我如何处理UIImageViews的图像分配:

int choice = (arc4random()%(50))+ 0;
switch (choice) {

    ...

    case 15:
        [self.a1 setImage:redApple];
        break;
    case 16:
        [self.a1 setImage:burger];
        break;
    case 17:
        [self.a1 setImage:fries];
        break;
    case 18:
        [self.a1 setImage:whiteCookie];
        break;
    case 19:
        [self.a1 setImage:blackCookie];
        break;
    case 20:
        [self.a1 setImage:pizza];
        break;
    case 21:
        [self.a1 setImage:orange];
        break;
    case 22:
        [self.a1 setImage:plyers];
        break;
    case 23:
        [self.a1 setImage:scissors];
        break;
    case 24:
        [self.a1 setImage:watch];
        break;
    case 25:
        [self.a1 setImage:clippers];
        break;
... etc

A1只是24个UIImageViews中的第一个......

知道我有一个按模式刷新视图并重新随机化UIImageViews图像的按钮也很重要...

0 个答案:

没有答案