gpt4 book ai didi

objective-c - 如何从字典数组中提取范围进行随机化? ( Objective-C )

转载 作者:行者123 更新时间:2023-11-29 04:35:21 25 4
gpt4 key购买 nike

我有一个字典数组存储在 plist 中,其中包含键和字符串,它们是我的测验应用程序的问题和答案。我正在屏幕上放置一个随机问题,但我想将问题的答案也以随机顺序放置在屏幕上。我该怎么做?

问题的引用方式如下:

-(void)displayQuestion: (NSDictionary *) Question 
{
[questionLabel setText:[Question objectForKey:@"Question"]];
[answer1 setText:[Question objectForKey:@"Answer1"]];
[answer2 setText:[Question objectForKey:@"Answer2"]];
[answer3 setText:[Question objectForKey:@"Answer3"]];
}

<dict>
<key>category</key>
<string>Elementary Pilot</string>
<key>Question</key>
<string>You are approaching a hang glider head-on and at approximately the same height. You should:</string>
<key>Answer1</key>
<string>Turn to your right?</string>
<key>Answer2</key>
<string>Turn to your left?</string>
<key>Answer3</key>
<string>Lose height rapidly?</string>
</dict>

最佳答案

使用此答案中找到的类别 What's the Best Way to Shuffle an NSMutableArray?

将你的答案放入 NSMutableArray 中,然后用 来打乱答案

NSMutableArray *answers = //get answers
[answers shuffle];

关于objective-c - 如何从字典数组中提取范围进行随机化? ( Objective-C ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11126781/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com