0

如何编写NSArray值以利用类似于此的变量NSString

Levelname=[NSString stringWithFormat:@"Background1Level%d.png",LevelNO];
    [backgroundimagview setImage:[UIImage imageNamed:Levelname]];

这是我需要转换以使用 LevelNO 变量的代码块:

        [character setImage:[UIImage imageNamed:@"character1_09.png"]];
        character.animationImages=[NSArray arrayWithObjects:
                              [UIImage imageNamed:@"character1_01.png"],
                              [UIImage imageNamed:@"character1_02.png"],
                              [UIImage imageNamed:@"character1_03.png"],
                              [UIImage imageNamed:@"character1_04.png"],nil ];
4

1 回答 1

4

用整数循环遍历它们,而不是“LevelNO”使用该整数。像这样的东西:

for(int i = 0; i < {number of levels here}, i++)
{
  Levelname=[NSString stringWithFormat:@"Background1Level%d.png",i];
  [myArray addObject:[UIImage imageWithName:Levelname];
}

确保保留一个数组并替换 myArray

于 2013-03-06T22:18:25.063 回答