我有一个使用xlform设置的部分,其中有一个bool字段,然后在它下面有一个文本字段。如果选择bool,我想禁用文本字段。我试过以下几种方法,但都没有用
if ([[self.form valueForKey:@"pay"] isEqualToValue:@(1)]){
row.disabled = YES;
} else {
row.required = YES;
}
[section addFormRow:row];有什么建议吗?这是文档,花了很多时间搜索,却找不到答案。
编辑:,我开始认为字典的值不会动态更新。这很奇怪,因为可以随时在视图控制器的其他部分访问字典。
编辑
- (void)formRowDescriptorValueHasChangedTwo:(XLFormRowDescriptor *)formRow value:(id)value
{
[value isEqual:[self.formValues valueForKey:@"pay"]];
if([formRow.tag isEqualToString:@"pay"] && [value isEqual:[NSNumber numberWithBool:YES]])
{
self.price.disabled = NO;
self.price.required = YES;
[self.tableView reloadRowsAtIndexPaths:@[[self.form indexPathOfFormRow:self.price]]
withRowAnimation:UITableViewRowAnimationNone];
}
}我成功了,但我有了新问题。
这是代码- (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)formRow oldValue:(id)oldValue newValue:(id)newValue {
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];
}
}当我单击第一行(现在)时,它会禁用相应的行,但当我单击第二行(支付)时,它会使现在禁用的行重新出现,并使我想要显示的行消失。
编辑通过将动画更改为UITableViewRowAnimationNone使其工作。
发布于 2015-02-11 23:51:25
下面是如何使用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“
https://stackoverflow.com/questions/28465469
复制相似问题