当我运行此代码并按“下一步”按钮时。我得到一个严重的过度错误。我想要它做的是检查用户输入的内容是否与给定标签的索引进行比较,每次用户输入正确答案时该索引都会发生变化。例如:naam.text =@“氟化钠”。那么formule.text 在“formules”中的索引必须与“namen”中的索引相同。
-(IBAction)next:(id)sender {
if ([formule.text isEqualToString:[formules objectAtIndex:x]]) {
x = arc4random() % x;
naam.text = [namen objectAtIndex:x];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
formules = [NSMutableArray arrayWithObjects:@"NaNO3",@"NaCH3COO",@"NaCl",@"NaBr",@"NaI",@"Na2SO4",@"NaF",@"Na2S",@"NaOH",@"Na2SO3",@"Na2CO3",@"Na3PO4",@"Na2O",nil];
namen = [NSMutableArray arrayWithObjects:@"Natriumnitraat",@"Natriumacetaat",@"Natriumchloride",@"Natriumbromide",@"Natriumjodide",@"Natriumsulfaat",@"Natriumfluoride",@"Natriumsulfide",@"Natriumhydroxide",@"Natriumsulfiet",@"NatriumCarbonaat",@"Natriumfosfaat",@"Natriumoxide", nil];
// Do any additional setup after loading the view from its nib.
x = arc4random() % [formules count];
naam.text = [namen objectAtIndex:x];
}
任何人都知道我的问题是什么以及如何解决它?