Objective c 在xlform上禁用条件行
我使用xlform设置了一个部分,其中有一个布尔字段,然后是一个文本字段。如果选择bool,我想禁用文本字段。我尝试了以下方法,但无效Objective c 在xlform上禁用条件行,objective-c,xlform,Objective C,Xlform,我使用xlform设置了一个部分,其中有一个布尔字段,然后是一个文本字段。如果选择bool,我想禁用文本字段。我尝试了以下方法,但无效 if ([[self.form valueForKey:@"pay"] isEqualToValue:@(1)]){ row.disabled = YES; } else { row.required = YES; } [section addFormRow:row]; 有什么建议吗?在文档中,花了大量时间搜索,却找不到答案 编辑:我开始认为字
if ([[self.form valueForKey:@"pay"] isEqualToValue:@(1)]){
row.disabled = YES;
} else {
row.required = YES;
}
[section addFormRow:row];
有什么建议吗?在文档中,花了大量时间搜索,却找不到答案
编辑:我开始认为字典的值不会动态更新。这很奇怪,因为可以随时在视图控制器的其他部分中访问字典
编辑
我让它工作了,但我有一个新问题
这是密码
-voidformRowDescriptorValueHasChanged:XLFormRowDescriptor*FormRowOldValue:IdodValue newValue:idnewValue
{
当我现在单击第一行时,它会禁用相应的行fine,但当我单击第二行pay时,它会使现在禁用的行重新出现,并使我希望显示在pay下的行消失
“编辑”通过将动画更改为UITableViewRowAnimationNone使其工作。以下是使用XLFormDescriptorDelegate执行此操作的方法。这将在表单上切换字段时更改状态
@interface SomeClass() <XLFormDescriptorDelegate>
@end
@implementation SomeClass
- (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)formRow oldValue:(id)oldValue newValue:(id)newValue
{
if([formRow.tag isEqualToString:@"boolFieldTag"] && [newValue boolValue])
{
self.otherRow.disabled = YES;
[self.tableView reloadRowsAtIndexPaths:@[[self.form indexPathOfFormRow:self.otherRow]]
withRowAnimation:UITableViewRowAnimationNone];
}
}
@end
在本例中,当我最初将该行添加到表单时,我将其设置为属性。或者,您可以使用:[self.form formRowWithTag:@someTag]我刚刚尝试过,结果是一样的。我开始认为,当行被填充时,字典不会被更新。@madgrand我更新了我的原始答案,以演示如何使用委托进行更新。我不确定你为什么要在你给出的示例中添加行,我假设行已经被添加。谢谢你的回答。我知道了我对您的建议进行了修改,并对其进行了处理,但仍然无法使其正常工作。我将函数添加到问题中。我担心该函数不会将您设置的值与行的值关联。有任何弥合此差距的建议吗?成功了。我只是忘了添加代理。感谢您的帮助帮助!我有一个新问题。添加到编辑中,你能提供建议吗?
if([formRow.tag isEqualToString:@"now"] && [newValue isEqual:[NSNumber numberWithBool:YES]])
{
self.time.disabled = YES;
[self.tableView reloadRowsAtIndexPaths:@[[self.form indexPathOfFormRow:self.time]]
withRowAnimation:UITableViewRowAnimationAutomatic];
}
if([formRow.tag isEqualToString:@"pay"] && [newValue isEqual:[NSNumber numberWithBool:YES]])
{
self.price.disabled = NO;
self.price.required = YES;
[self.tableView reloadRowsAtIndexPaths:@[[self.form indexPathOfFormRow:self.price]]
withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
@interface SomeClass() <XLFormDescriptorDelegate>
@end
@implementation SomeClass
- (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)formRow oldValue:(id)oldValue newValue:(id)newValue
{
if([formRow.tag isEqualToString:@"boolFieldTag"] && [newValue boolValue])
{
self.otherRow.disabled = YES;
[self.tableView reloadRowsAtIndexPaths:@[[self.form indexPathOfFormRow:self.otherRow]]
withRowAnimation:UITableViewRowAnimationNone];
}
}
@end