OStack程序员社区-中国程序员成长平台

标题: ios - XLForms集成空tableView [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 08:45
标题: ios - XLForms集成空tableView

我找到了图书馆 XLFORMS我希望在我的应用程序中使用它。问题是它没有显示任何行和部分,只是一个空的 tableView。我在我的 Storyboard中创建了一个 View Controller ,我在其中删除了 View ,因此它只是完全空的 View Controller 。然后我将示例代码添加到 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];



Best Answer-推荐答案


我也在做同样的事情。代码不应在 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];

}

除此之外,您还需要确保您的 init 看起来像这样:

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

        [self initform];

    }
    return self;
}

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

        [self initform];

    }
    return self;
}

希望这对您和我一样有效。祝你好运!

关于ios - XLForms集成空tableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24969508/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4