2009-06-30 7 views
1

Plus de trucs iPhone ... Est-ce que quelqu'un sait comment je peux réduire ce code. Donc je n'ai pas besoin d'écrire toutes les images.Comment rationaliser mon code - UIImage imageNamed:

Merci beaucoup

bMon01.animationImages = [NSArray arrayWithObjects: 
        [UIImage imageNamed:@"mon01_0001.png"], 
        [UIImage imageNamed:@"mon01_0002.png"], 
        [UIImage imageNamed:@"mon01_0003.png"], 
        [UIImage imageNamed:@"mon01_0004.png"], 
        [UIImage imageNamed:@"mon01_0005.png"], 
        [UIImage imageNamed:@"mon01_0006.png"], 
        [UIImage imageNamed:@"mon01_0007.png"], 
        [UIImage imageNamed:@"mon01_0008.png"], 
        [UIImage imageNamed:@"mon01_0009.png"], 
        [UIImage imageNamed:@"mon01_0010.png"], 
        [UIImage imageNamed:@"mon01_0011.png"], 
        [UIImage imageNamed:@"mon01_0012.png"], 
        [UIImage imageNamed:@"mon01_0013.png"], 
        [UIImage imageNamed:@"mon01_0014.png"], 
        [UIImage imageNamed:@"mon01_0015.png"], 
        [UIImage imageNamed:@"mon01_0016.png"], 
        [UIImage imageNamed:@"mon01_0017.png"], 
        [UIImage imageNamed:@"mon01_0018.png"], 
        [UIImage imageNamed:@"mon01_0019.png"], 
        [UIImage imageNamed:@"mon01_0020.png"], 
        [UIImage imageNamed:@"mon01_0021.png"], 
        [UIImage imageNamed:@"mon01_0022.png"], 
        [UIImage imageNamed:@"mon01_0023.png"], 
        [UIImage imageNamed:@"mon01_0024.png"], 
        [UIImage imageNamed:@"mon01_0025.png"], nil]; 
+2

Comme une note future à tous ceux qui liront ceci: Si vous commencez à écrire du code de l'iPhone, tout code pour cette matière, et vous vous répétez presque du tout, ou quelque chose semble fastidieux, il y a 100% de chances que vous puissiez faire fonctionner l'ordinateur pour vous. – Sneakyness

Répondre

8

Est-ce que cette aide:

NSMutableArray *array = [NSMutableArray array]; 
for (int i = 1; i <= 25; i++) 
    [array addObject:[UIImage imageNamed:[NSString stringWithFormat:@"mon01_%04d.png",i]]]; 

bMon01.animationImages = array; 
+0

OUI! Merci Diederik! –

Questions connexes