XLForm如何添加两个BooleanCheck导入互斥关系

时间:2016-04-04 14:58:22

标签: ios xlform

我在表单中添加了两个BooleanCheck(A和B)。

我希望表单可以做到这一点 当我点击A.它的值将为YES; 然后我点击B. B值为YES,A为NO。

简单地说,他们中只有一个可以是isChecked

-(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
{
    // super implmentation MUST be called
    [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
    if ([rowDescriptor.tag isEqualToString:@"aCheck"]){
      if(aCheck.value==YES)
          bCheck.value = NO;
        }
    }else if ([rowDescriptor.tag isEqualToString:@"bCheck"]){
      if(bCheck.value==YES)
          aCheck.value = NO;
    }
}

1 个答案:

答案 0 :(得分:1)

我不确定您的aCheck和bCheck是什么,但想法是在更改受影响的rowDescriptors的值后重新加载tableview或行

-(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
{
    // super implmentation MUST be called
    [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
    if ([rowDescriptor.tag isEqualToString:@"aCheck"]){
      if(aCheck.value==YES)
          bCheck.value = NO;
        }
    }else if ([rowDescriptor.tag isEqualToString:@"bCheck"]){
      if(bCheck.value==YES)
          aCheck.value = NO;
    }
    //
    // The idea is to reloadData or reload indexPaths
    //
    XLFormRowDescriptor *rowA = [self.form formRowWithTag:@"aCheck"];
    XLFormRowDescriptor *rowB = [self.form formRowWithTag:@"bCheck"];
    NSIndexPath *ipA = [self.form indexPathOfFormRow:rowA];
    NSIndexPath *ipB = [self.form indexPathOfFormRow:rowB];
    [self.tableView reloadRowsAtIndexPaths:@[ipA,ipB] withRowAnimation:UITableViewRowAnimationNone];
}