如何编写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 ];
答案 0 :(得分: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