XLForm—根据用户输入动态添加行



我正在尝试根据用户的输入在表单中添加更多行。

例如,我有一个字段询问我想要向表单添加多少行。如果输入为5,则将生成另外5行并将其附加到表单中。

到目前为止,XLForm有能力添加单行(例如多值表单),我在想如果我能做同样的事情,但批量而不是每次只添加一行。

这可能吗?

我处理XLForm已经有一段时间了,但我认为这样做会很好:

-(void) formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)formRow oldValue:(id)oldValue newValue:(id)newValue {
    [super formRowDescriptorValueHasChanged:formRow oldValue:oldValue newValue:newValue];
    NSNumber *newVal = [newValue valueData];
    int count = newVal.intValue; //5
    for(int i=0; i<count; i++) {
        NSString *title = [NSString stringWithFormat:@"title %d",i+1];
        XLFormRowDescriptor *row = [XLFormRowDescriptor formRowDescriptorWithTag:title rowType:XLFormRowDescriptorTypeText];
        [row.cellConfigAtConfigure setObject:title forKey:@"textField.placeholder"];
        [self.form addFormRow:row afterRowTag:someOtherRow.tag];
    }
}

最新更新