我可能需要一些帮助。
我在Objective-C项目中使用XLForm。我有一个带拾取器的第一排,你有四种不同的选择。然后是第二个选择器。但是,只有在第一个选择器中选择了某个值时,才能使用第二个选择器。
我知道github网站上有描述,但我真的不明白该怎么做。所以请帮我这样做。
以下是我的代码的相关部分:
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”,则应隐藏第二个选择器。
非常感谢您的帮助。
答案 0 :(得分:0)
对于你的第二个XLFormRowDescriptor
,你应该:
secondRow.hidden = [NSString stringWithFormat:@"$%@ == 20", firstRow];
firstRow
是第一个XLFormRowDescriptor
。
这实际上创建了一个NSPredicate,只要值发生变化就会自动评估它并适当地设置可见性。
取自XLForm的例子:
例如,您可以将以下字符串设置为一行(第二行) 当前一行(第一行)包含值时,使其消失 "隐藏"
second.hidden = [NSString stringWithFormat:@"$%d contains[c] 'hide'", [first.value intValue]];
编辑:我更改了谓词以使用NSNumber值。