SDForms 是一个开源的 iOS forms 库,允许创建基于 UITableView 的动态表单。它提供了不同类型的字段,如文本字段、选择字段、日期选择字段、开关字段、滑动条字段等。它还允许自动将字段的值映射到对象属性。
这是一个简单的示例。对于更高级的使用,请查看示例项目。
self.form = [[SDForm alloc] initWithTableView:self.tableView];
self.form.delegate = self;
self.form.dataSource = self;
SDTextFormField *name = [[SDTextFormField alloc] initWithObject:self.person relatedPropertyKey:@"name"];
name.title = @"Name";
name.placeholder = @"Name";
name.cellType = SDTextFormFieldCellTypeTextAndLabel;
- (NSInteger)numberOfSectionsForForm:(SDForm *)form
{
return self.sections.count;
}
- (NSInteger)form:(SDForm *)form numberOfFieldsInSection:(NSInteger)section
{
NSMutableArray *fields = [self.sections objectAtIndex:section];
return fields.count;
}
- (SDFormField *)form:(SDForm *)form fieldForRow:(NSInteger)row inSection:(NSInteger)section
{
NSArray *fields = [self.sections objectAtIndex:section];
return [fields objectAtIndex:row];
}