XLForms集成空tableView

时间:2014-07-26 09:21:38

标签: ios objective-c uitableview xlform

我找到了我希望在我的应用中使用的库XLFORMS。问题是它没有显示任何行和节只是一个空的tableView。我在我的故事板中创建了一个viewcontroller,我已经删除了视图,因此它只是一个完全空的viewController。然后我将示例代码添加到ViewDidLoad方法,但只是一个空的tableView?为了显示库中的字段,我还需要什么。

XLFormDescriptor * form;
XLFormSectionDescriptor * section;
XLFormRowDescriptor * row;

form = [XLFormDescriptor formDescriptorWithTitle:@"Add Event"];

// First section
section = [XLFormSectionDescriptor formSection];
[form addFormSection:section];

// Title
row = [XLFormRowDescriptor formRowDescriptorWithTag:@"title" rowType:XLFormRowDescriptorTypeText];
[row.cellConfigAtConfigure setObject:@"Title" forKey:@"textField.placeholder"];
[section addFormRow:row];

// Location
row = [XLFormRowDescriptor formRowDescriptorWithTag:@"location" rowType:XLFormRowDescriptorTypeText];
[row.cellConfigAtConfigure setObject:@"Location" forKey:@"textField.placeholder"];
[section addFormRow:row];

// Second Section
section = [XLFormSectionDescriptor formSection];
[form addFormSection:section];

// All-day
row = [XLFormRowDescriptor formRowDescriptorWithTag:@"all-day" rowType:XLFormRowDescriptorTypeBooleanSwitch title:@"All-day"];
[section addFormRow:row];

// Starts
row = [XLFormRowDescriptor formRowDescriptorWithTag:@"starts" rowType:XLFormRowDescriptorTypeDateTimeInline title:@"Starts"];
row.value = [NSDate dateWithTimeIntervalSinceNow:60*60*24];
[section addFormRow:row];

3 个答案:

答案 0 :(得分:4)

我正在做同样的事情。代码不应该在ViewDidLoad中。

因此,在.m文件中创建一个void,然后输入代码,使其如下所示:

-(void)initform
{

    XLFormSectionDescriptor * section;
    XLFormRowDescriptor * row;

    self.form = [XLFormDescriptor formDescriptorWithTitle:@"Add Event"];

    // First section
    section = [XLFormSectionDescriptor formSection];
    [self.form addFormSection:section];

    // Title
    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"title" rowType:XLFormRowDescriptorTypeText];
    [row.cellConfigAtConfigure setObject:@"Title" forKey:@"textField.placeholder"];
    [section addFormRow:row];

    // Location
    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"location" rowType:XLFormRowDescriptorTypeText];
    [row.cellConfigAtConfigure setObject:@"Location" forKey:@"textField.placeholder"];
    [section addFormRow:row];

    // Second Section
    section = [XLFormSectionDescriptor formSection];
    [self.form addFormSection:section];


// All-day
row = [XLFormRowDescriptor formRowDescriptorWithTag:@"all-day" rowType:XLFormRowDescriptorTypeBooleanSwitch title:@"All-day"];
[section addFormRow:row];


    // Starts
    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"starts" rowType:XLFormRowDescriptorTypeDateTimeInline title:@"Starts"];
    row.value = [NSDate dateWithTimeIntervalSinceNow:60*60*24];
    [section addFormRow:row];

}

除此之外,您需要确保您的插图如下所示:

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization

        [self initform];

    }
    return self;
}

- (id)initWithCoder:(NSCoder *)aDecoder;
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        // Custom initialization

        [self initform];

    }
    return self;
}

希望这对你有用,就像对我一样。祝好运! :)

答案 1 :(得分:0)

您可能错过的另一件事是将表视图(添加到您希望表单呈现的空视图控制器中的视图)连接到XLFormViewController中的tableView插座:

@property IBOutlet UITableView * tableView;

答案 2 :(得分:0)

使用XLFormViewController而不是UIViewController对ViewController进行子类化。创建表单后添加1行代码self.form = form