Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 洗牌 NSMutableArray 的最佳方法是什么?
我正在开发一个应用程序。我有一个数组。包含 5 个值 1、2、3、4、5。我想以随机方式显示这些值。例如,第一次显示 3 2 4 5 1。第二次 1 3 2 4 5.每次我想更改订单时都这样。所以请告诉我如何做这个。
示例代码:
int i = arc4random() % 4; NSString value = [arr objectAtIndex: i] [arr removeObjectAtIndex: i];
重复这些步骤,直到你有一个空数组。