目前正在加载我的声音
NSString * strName = [NSString stringWithFormat:@"soundpack%ld", (long) (value+1)];
获取每个声音的值。
现在我想将它从数组中拉出来。看起来像这样:
NSMutableArray * sounds = [NSMutableArray arrayWithObjects: @"soundpack1", @"soundpack2", @"soundpack3", @"soundpack4", @"soundpack5", @"soundpack6", @"soundpack7", @"soundpack8", @"soundpack9", nil];
NSUInteger count = [sounds count];
for (NSUInteger i = 0; i < count; ++i) {
NSInteger nElements = count - i;
NSInteger n = arc4random_uniform((u_int32_t )nElements) + i;
[sounds exchangeObjectAtIndex:i withObjectAtIndex:n];
}
NSString * strName0 = [sounds objectAtIndex:1];
好吧,现在我已经改组了声音。现在我想像以前一样用特定的值初始化。
类似的东西:
NSString * strName = [sounds objectAtIndex:%ld, (long) (value+1)];
或
NSString * strName = [sounds objectAtIndex:@"%ld", (long) (value+1)];
没用。但我不知道,现在该怎么做......
答案 0 :(得分:1)
尝试更改此行
NSString * strName = [sounds objectAtIndex:@"%ld", (long) (value+1)];
到
NSString * strName = [sounds objectAtIndex:(long) (value+1)];
答案 1 :(得分:0)
为什么不要在洗牌后使用相同的片段?
NSString * strName = [NSString stringWithFormat:@"soundpack%ld", (long) (value+1)];