我正在玩我的应用程序,并且切换 UISwitch 的速度非常快(谁能抗拒?)。所以,我非常快地切换了 10-15 次,一个数组应该包含我切换到的表视图单元格中的数据,或者有同一个单元格的额外副本,或者只有一个副本(正确的情况)或里面根本没有数据。如果以正常速度切换,该应用程序可以正常工作。
我很确定这种情况不会真正发生在我的用户身上,但我仍然很好奇它为什么会发生。
谢谢, 泰加
编辑:添加代码。每次切换开关时都会调用此方法。
-(void)saveOptionChanged:(id) sender
{
UISwitch *sw = (UISwitch *) sender;
//int tag = current.tag;
BOOL status = (BOOL) [sw isOn];
NSInteger tag = sw.tag;
NSInteger row1 = tag%1000;
NSInteger section1 = (tag - row1)/1000;
DiagDetails *temp = [preferences getDiagElementAt:section1 row:row1];
temp.ICD9Code= [temp.ICD9Code stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
temp.ICD9Desc= [temp.ICD9Desc stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSLog(@"Adding %@ - %@",temp.ICD9Code, temp.ICD9Desc);
NSLog(@"tag = %ld, row = %ld, section = %ld",tag,row1,section1);
if(status) {
BOOL returnVal = YES;
returnVal = [currentPatient addICD9Code:temp];
if(!returnVal) {
UIAlertView *error = [[UIAlertView alloc] initWithTitle:@"Diagnosis add error" message:@"" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[error show];
[error release];
[sw setOn:NO];
}
}
else {
DiagDetails *temp = [preferences getDiagElementAt:section1 row:row1];
[currentPatient removeICD9Code:temp.ICD9Code];
}
}