我可能需要一些帮助。
我在我的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];
这是两个选择器。我想我应该在形式上做一些事情 RowDescriptorValueHasChanged-方法,但我不知道是什么。如果第一个选取器的值为"20",则应隐藏第二个选取器。
非常感谢您的帮助。
对于您的第二个XLFormRowDescriptor
,您应该:
secondRow.hidden = [NSString stringWithFormat:@"$%@ == 20", firstRow];
firstRow
是第一个XLFormRowDescriptor
.
这实际上创建了一个 NSPredicate,每当值更改时都会自动评估该 NSPredicate,并适当地设置可见性。
取自XLForm的例子:
例如,可以将以下字符串设置为行(秒)到 使其在上一行(第一行)包含值时消失 "隐藏"。
second.hidden = [NSString stringWithFormat:@"$%d contains[c] 'hide'", [first.value intValue]];
编辑:我更改了谓词以使用 NSNumber 值。