所以,这是交易。 我的xib中有16个按钮,每个按钮都在其控制器中实例化,代码如下:
IBOutlet UIButton *left1;
IBOutlet UIButton *left2;
IBOutlet UIButton *left3;
IBOutlet UIButton *left4;
IBOutlet UIButton *left5;
IBOutlet UIButton *left6;
IBOutlet UIButton *left7;
IBOutlet UIButton *left8;
IBOutlet UIButton *right1;
IBOutlet UIButton *right2;
IBOutlet UIButton *right3;
IBOutlet UIButton *right4;
IBOutlet UIButton *right5;
IBOutlet UIButton *right6;
IBOutlet UIButton *right7;
IBOutlet UIButton *right8;
当按下其中一个按钮时,它应该根据按下的按钮按下具有对象的视图。我是这样做的:
if (upperLower.selectedSegmentIndex == 0) {
if (sender == left1) {
aTooth = [aPatient.teeth objectForKey:@"11"];
} else if (sender == left2) {
aTooth = [aPatient.teeth objectForKey:@"12"];
} else if (sender == left3) {
aTooth = [aPatient.teeth objectForKey:@"13"];
} else if (sender == left4) {
aTooth = [aPatient.teeth objectForKey:@"14"];
} else if (sender == left5) {
aTooth = [aPatient.teeth objectForKey:@"15"];
} else if (sender == left6) {
aTooth = [aPatient.teeth objectForKey:@"16"];
} else if (sender == left7) {
aTooth = [aPatient.teeth objectForKey:@"17"];
} else if (sender == left8) {
aTooth = [aPatient.teeth objectForKey:@"18"];
} else if (sender == right1) {
aTooth = [aPatient.teeth objectForKey:@"21"];
} else if (sender == right2) {
aTooth = [aPatient.teeth objectForKey:@"22"];
} else if (sender == right3) {
aTooth = [aPatient.teeth objectForKey:@"23"];
} else if (sender == right4) {
aTooth = [aPatient.teeth objectForKey:@"24"];
} else if (sender == right5) {
aTooth = [aPatient.teeth objectForKey:@"25"];
} else if (sender == right6) {
aTooth = [aPatient.teeth objectForKey:@"26"];
} else if (sender == right7) {
aTooth = [aPatient.teeth objectForKey:@"27"];
} else if (sender == right8) {
aTooth = [aPatient.teeth objectForKey:@"28"];
}
}
else {
if (sender == left1) {
aTooth = [aPatient.teeth objectForKey:@"41"];
} else if (sender == left2) {
aTooth = [aPatient.teeth objectForKey:@"42"];
} else if (sender == left3) {
aTooth = [aPatient.teeth objectForKey:@"43"];
} else if (sender == left4) {
aTooth = [aPatient.teeth objectForKey:@"44"];
} else if (sender == left5) {
aTooth = [aPatient.teeth objectForKey:@"45"];
} else if (sender == left6) {
aTooth = [aPatient.teeth objectForKey:@"46"];
} else if (sender == left7) {
aTooth = [aPatient.teeth objectForKey:@"47"];
} else if (sender == left8) {
aTooth = [aPatient.teeth objectForKey:@"48"];
} else if (sender == right1) {
aTooth = [aPatient.teeth objectForKey:@"31"];
} else if (sender == right2) {
aTooth = [aPatient.teeth objectForKey:@"32"];
} else if (sender == right3) {
aTooth = [aPatient.teeth objectForKey:@"33"];
} else if (sender == right4) {
aTooth = [aPatient.teeth objectForKey:@"34"];
} else if (sender == right5) {
aTooth = [aPatient.teeth objectForKey:@"35"];
} else if (sender == right6) {
aTooth = [aPatient.teeth objectForKey:@"36"];
} else if (sender == right7) {
aTooth = [aPatient.teeth objectForKey:@"37"];
} else if (sender == right8) {
aTooth = [aPatient.teeth objectForKey:@"38"];
}
}
toothController.aTooth = aTooth;
toothController.aPatient = aPatient;
if (aTooth) {
[self.navigationController pushViewController:toothController animated:YES];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Tooth not found" message:@"The patient doesn't have that tooth" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
}
[aTooth release];
现在问题是我无法弄清楚为什么如果我按下left1,left2或left3它完美无缺。现在,如果我按下left4它会崩溃,有时会有异常(NSCFArray号码无法识别的选择器发送blalbal),有时没有它。编号为11,12,13和14的所有齿都存在于阵列中。我只尝试过那些因为我太懒而无法创造36个。但是为什么它只能用于14号呢?
我一直在努力解决这个问题几个小时失败。 任何有帮助的帮助。
更新:(最后一次更新错误)我从解析牙齿的xml中删除了牙齿编号14,并添加了牙齿编号15.问题仍然存在于15号牙齿并显示正确的信息(牙齿没有存在)牙齿数14。
更新2:在[aTooth发布]之后我添加了“aTooth = nil”,现在我可以进入15号牙齿,但是我无法接触任何牙齿两次。一旦我找到了一颗牙齿,我就不能再回头去了。
答案 0 :(得分:1)
objectForKey:
是一种NSDictionary
方法。您收到的异常表明teeth
是NSArray
。我相信你想要使用
aTooth = [aPatient.teeth objectAtIndex:some-index];
答案 1 :(得分:0)
[aTooth release]
- ???所以你在从字典中检索它后发布了对象?