0

我可能需要一些帮助。

我在我的 Objective-C 项目中使用 XLForm。我有一个带选择器的第一行,您有四个不同的选项。然后是第二个选择器。但是只有在第一个选择器中选择了某个值时,第二个选择器才应该可用。

我知道 github-site 上有描述,但我真的不明白该怎么做。所以请帮我做这件事。

以下是我的代码的相关部分:

row = [XLFormRowDescriptor formRowDescriptorWithTag:@"repeat" rowType:XLFormRowDescriptorTypeSelectorPickerViewInline title:@"Wiederholen:" ];
row.cellClass = [LehrerXLFormInlineSelectorCell class];

NSMutableArray *selectionArray = [NSMutableArray array];

for (NSNumber *item in [APIDataReplacement appointmentRepeatingList]) {
    NSString *title = [APIDataReplacement appointmentRepeatingToString:item.intValue];
    [selectionArray addObject:[XLFormOptionsObject formOptionsObjectWithValue:item displayText:title]];
}

row.selectorOptions = selectionArray;
if ([selectionArray count] == 0) {
    [row setDisabled:@YES];
}

if (aItem) {

    int repeatingID = [[aItem appointmentRepeatingId] intValue];
    NSString *title = [APIDataReplacement appointmentRepeatingToString:repeatingID];
    row.value = [XLFormOptionsObject formOptionsObjectWithValue:[NSNumber numberWithInt:repeatingID] displayText:title];

}else{

    NSNumber *first = [[APIDataReplacement appointmentRepeatingList] firstObject];
    NSString *title = [APIDataReplacement appointmentRepeatingToString:first.intValue];
    row.value = [XLFormOptionsObject formOptionsObjectWithValue:first displayText:title];
}

[section addFormRow:row];


section = [XLFormSectionDescriptor formSectionWithTitle:@""];
[form addFormSection:section];


row = [XLFormRowDescriptor formRowDescriptorWithTag:@"weekday" rowType:XLFormRowDescriptorTypeSelectorPickerViewInline title: @"Wochentag:"];
row.cellClass = [LehrerXLFormInlineSelectorCell class];

NSMutableArray *selectionArray1 = [NSMutableArray array];

for (NSNumber *item in [APIDataReplacement dayList]) {
    NSString *title = [APIDataReplacement dayToString:item.intValue];
    [selectionArray1 addObject:[XLFormOptionsObject formOptionsObjectWithValue:item displayText:title]];
}

row.selectorOptions = selectionArray1;

if (aItem) {

    // AppointmentRepeating *currentRepeat = [aItem appointmentRepeating];
    int dayID = [[aItem startday] intValue];
    NSString *title = [APIDataReplacement dayToString:dayID];
    row.value = [XLFormOptionsObject formOptionsObjectWithValue:[NSNumber numberWithInt:dayID] displayText:title];

}else{

    NSNumber *first = [[APIDataReplacement dayList] firstObject];
    NSString *title = [APIDataReplacement dayToString:first.intValue];
    row.value = [XLFormOptionsObject formOptionsObjectWithValue:first displayText:title];
}

[section addFormRow:row];


section = [XLFormSectionDescriptor formSectionWithTitle:@""];
[form addFormSection:section];

这是两个选择器。我想我应该在 formRowDescriptorValueHasChanged 方法中做一些事情,但我不知道是什么。如果第一个选择器的值是“20”,那么第二个选择器应该被隐藏。

非常感谢您的帮助。

4

1 回答 1

0

对于您的第二个XLFormRowDescriptor,您应该:

secondRow.hidden = [NSString stringWithFormat:@"$%@ == 20", firstRow];

firstRow是第一个XLFormRowDescriptor

这实际上创建了一个 NSPredicate ,它会在值更改时自动评估并适当地设置可见性。

取自 XLForm 的示例:

例如,您可以将以下字符串设置为一行(第二个),以使其在前一行(第一行)包含值“隐藏”时消失。

second.hidden = [NSString stringWithFormat:@"$%d contains[c] 'hide'", [first.value intValue]];

编辑:我将谓词更改为使用 NSNumber 值。

于 2017-10-16T13:53:06.350 回答