所以我是编程新手,并且已经坚持了好几天......我有一个数组,如图所示
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com /DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>question</key>
<string>2 + 2 = ?</string>
<key>A</key>
<string>2</string>
<key>B</key>
<string>7</string>
<key>C</key>
<string>3</string>
</dict>
<dict>
<key>question</key>
<string>2 + 3 = ?</string>
<key>A</key>
<string>5</string>
<key>B</key>
<string>2</string>
<key>C</key>
<string>6</string>
</dict>
</array>
</plist>
然后我想为每个存储一个数组。然后,我在故事板中为每个标签设置了一个标签,并希望将每个键分配给不同的标签,但我似乎做错了。这是我的代码
- (void)showNextQuestion
{
NSArray *rootArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"question" ofType:@"plist"]];
int numItems = [rootArray count];
currentQuestion = -1;
currentQuestion++;
NSMutableArray *question = [NSMutableArray arrayWithCapacity:numItems];
NSMutableArray *A = [NSMutableArray arrayWithCapacity:numItems];
NSMutableArray *B = [NSMutableArray arrayWithCapacity:numItems];
NSMutableArray *C = [NSMutableArray arrayWithCapacity:numItems];
for (NSDictionary *itemData in rootArray) {
[question addObject:[itemData objectForKey:@"question"]];
[A addObject:[itemData objectForKey:@"A"]];
[B addObject:[itemData objectForKey:@"B"]];
[C addObject:[itemData objectForKey:@"C"]];
self.questionasked.text =question;
self.answer1.text = A;
self.answer2.text = B;
self.answer3.text = C;
}
}
4个标签是问题,answer1,answer2,answer3......我如何正确分配它