I was playing around my app and I was toggling a UISwitch really fast (who can resist?). So, I toggled it really fast for 10-15 times, an array that should contain the data from the table view cell that I have my switch in, either has extra copies of the same cell or just one copy (the correct case) or no data in it at all. The app works fine if it's toggled at normal speed.
I'm pretty sure this scenario won't really happen with my users, but I'm still curious as to why it's happening.
Thanks, Teja
Edit: Adding code. This method gets called each time the switch is toggled.
-(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];
}
}