XLForms integration empty tableView

醉酒当歌 提交于 2019-12-10 10:39:25

问题


I've found the library XLFORMS which i wish to use in my app. The problem is that it is not showing any rows and section just an empty tableView. i've in my storyboard created a viewcontroller where i've deleted the view so its just and completely empty viewController. Then i've added the example code to the ViewDidLoad method, but just a empty tableView? What do i need more in order to show the fields from the library.

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];

回答1:


I am doing the same thing. The code should not be in ViewDidLoad.

So, create a void in your .m file, and enter the code so it looks like this:

-(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];

}

In addition to do this, you need to make sure your inits look like this:

- (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;
}

Hope this works as well for you as it did for me. Good luck! :)




回答2:


Another thing you might have missed is hooking up your table view (the one added to the empty view controller in which you expect the form to render) to the tableView outlet in XLFormViewController:

@property IBOutlet UITableView * tableView;



回答3:


Subclass your ViewController with XLFormViewController and not UIViewController. After creating form add 1 line of code self.form = form.



来源:https://stackoverflow.com/questions/24969508/xlforms-integration-empty-tableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!