代码之家  ›  专栏  ›  技术社区  ›  Tejaswi Yerukalapudi

多次切换快速切换

  •  0
  • Tejaswi Yerukalapudi  · 技术社区  · 14 年前

    特加

    编辑:添加代码。每次切换开关时都会调用此方法。

    -(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];
    }
    }
    
    1 回复  |  直到 14 年前
        1
  •  0
  •   Shaggy Frog    14 年前

    如果我不得不猜测,您触发事件的速度太快,以至于它们可能合并或被跳过,所以如果您根据调用事件处理程序的次数隐式设置状态,那么您可能会失去同步。(相反,您应该显式地确定 UISwitch --打开或关闭——在事件处理程序中)必须显示更多代码才能确定。的事件处理程序的代码 更改状态事件。