您知道如何用一系列图片随机填充表格吗?
我正在尝试创建一个记忆游戏,但我不知道如何用数组中的图片随机填充我的单元格。我刚刚开始主要针对 iOS 进行 Xcode 编程,并且在 Stack Overflow 上搜索了几天,但似乎找不到答案。要么就是我不太明白你们专业人士所说和解释的内容。
有人可以请启发我吗?
I'm trying to create a memory game and I'm stuck with no idea how to randomly populate my cells with pictures from an array. I've just started out Xcode programming mainly for the iOS and I have searched for days on Stack Overflow but I can't seem to find an answer. Either that or I don't really understand what you professionals have said and explained.
Could anyone kindly please enlighten me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此代码将采用包含图片的 NSArray 并生成一个包含随机顺序图片的新数组。然后,您可以保存新数组并将其在表的数据源中使用。
This code will take an NSArray containing the pictures and produce a new array containing the pictures in random order. Then, you can save the new array and use it in your data source for your table.
如果您始终拥有相同的元素集,并且只想将它们放入随机顺序,那么我建议您阅读 Fisher-Yates 洗牌算法 (http://en.wikipedia.org/wiki/Fisher–耶茨_洗牌)。这与您在纸牌游戏中随机化一副纸牌或您想要排列的任何其他有限集的过程相同。
If you always have the same set of elements, and you just want to put them into a randomized order, then I recommend you read up on the Fisher-Yates shuffling algorithm (http://en.wikipedia.org/wiki/Fisher–Yates_shuffle). It's the same process you'd use to randomize a deck of cards in a card game, or any other finite set you want to permute.