目前即時加載我的聲音與如何初始化nsstring的值?
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)];
沒有工作。但我不知道,現在該怎麼辦...
非常感謝!工作中! – iOSBeginner