我有一个包含许多测验项目的 plist 是通过使用 arc4random () 随机拉出的,我想在显示后删除每个项目,以免重复问题,我尝试使用[thisArray removeObjectAtIndex:r];
,但项目仍然显示。有任何想法吗?
NSString *path = [[NSBundle mainBundle] pathForResource:@"initialquestions" ofType:@"plist"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:path]) {
NSLog(@"The file exists");
}
else {
NSLog(@"The file does not exist");
}
NSMutableArray *thisArray = [[NSMutableArray alloc] initWithContentsOfFile:path];
NSLog(@"The array count: %i", [thisArray count]);
for (int i = 0; i < [thisArray count]; i++) {
id obj;
int r = arc4random() % [thisArray count];
if(r<[thisArray count]){
obj=[thisArray objectAtIndex:r];
}
else{
//error message
}
QuestionTitle.text = [[thisArray objectAtIndex:r] objectForKey:@"QuestionTitle"];
[btnA setTitle:[[thisArray objectAtIndex:r] objectForKey:@"A"] forState:UIControlStateNormal];
[btnB setTitle:[[thisArray objectAtIndex:r] objectForKey:@"B"] forState:UIControlStateNormal];
[btnC setTitle:[[thisArray objectAtIndex:r] objectForKey:@"C"] forState:UIControlStateNormal];
[thisArray removeObjectAtIndex:r];
}