how can XLForm add two BooleanCheck importing mutex relationship

62 views Asked by At

I add two BooleanCheck in my form(A and B).

I want the form can do this when I click A. its value will be YES; and then I click B. B Value be YES and A be NO.

Simply, they only one of them can be 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

There are 1 answers

0
Ted On

I'm not sure what is your aCheck and bCheck, but the idea is to reload the tableview or rows after changing the values of the affected rowDescriptors

-(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];
}