Latest 0.3.0
Homepage https://github.com/enriquez/MEDeclarativeTable
License MIT
Platforms ios 7.0, requires ARC
Authors

Describe the structure of your UITableView‘s sections and rows in an object oriented way. Useful for building small and mostly static tables such as forms, settings, menus, etc… We prefer readability over memory efficiency, so it is not recommended to use this with tables that may have a large number of cells.

To run the example project, clone the repo, and run pod install from the Example directory first.

Getting Started

MEDeclarativeTable acts as a UITableViewDataSource and UITableViewDelegate for your UITableView. Once setup, you configure your sections and rows through MEDeclarativeTable.

Setup

Create an MEDeclarativeTable instance and set it as the table’s data source and delegate.

MEDeclarativeTable *declarativeTable = [[MEDeclarativeTable alloc] init];
self.tableView.dataSource = declarativeTable;
self.tableView.delegate   = declarativeTable;

Table Sections

All tables need at least one section. Sections are represented by the MEDeclarativeTableSection class.

MEDeclarativeTableSection *section = [[MEDeclarativeTableSection alloc] init];

From here, you can configure the section’s header and footer. The example below sets the header title. See MEDeclarativeTableSection.h for more options.

section.headerTitle  = @"Section Title";

Add the section to the table.

[declarativeTable addSection:section];

Table Rows

Now that we have a section, we can create some rows and add them to it. The following example creates three rows.

MEDeclarativeTableRow *nameRow = [MEDeclarativeTableRow alloc] initWithStyle:MEDeclarativeTableRowStyleValue2];
nameRow.textLabelText          = @"Name";
nameRow.detailTextLabelText    = @"Mike Enriquez";

MEDeclarativeTableRow *emailRow = [MEDeclarativeTableRow alloc] initWithStyle:MEDeclarativeTableRowStyleValue2];
emailRow.textLabelText          = @"Email";
emailRow.detailTextLabelText    = @"[email protected]";

MEDeclarativeTableRow *deleteRow = [MEDeclarativeTableRow alloc] init];
deleteRow.textLabelText          = @"Delete Contact";
deleteRow.configureCell = ^(UITableViewCell *cell) {
    cell.textLabel.textAlignment = NSTextAlignmentCenter;
    cell.textLabel.textColor     = [UIColor redColor];
};
deleteRow.didSelectAction = ^() {
    NSLog(@"TODO: Delete Contact tapped");
};

[section setRows:@[ nameRow, emailRow, deleteRow ]];

A row can contain a custom view. Use the MEDeclarativeTableRowStyleCustomView style and set customView. The row’s height will automatically be set based on the height of the custom view.

MEDeclarativeTableRow *row = [MEDeclarativeTableRow alloc] initWithStyle:MEDeclarativeTableRowStyleCustomView];
row.customView = self.myCustomView;

[section addRow:row];

Installation

MEDeclarativeTable is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "MEDeclarativeTable"

License

MEDeclarativeTable is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "MEDeclarativeTable",
    "version": "0.3.0",
    "summary": "Describe the structure of your `UITableView`'s sections and rows in an object oriented way.",
    "description": "Describe the structure of your `UITableView`'s sections and rows in an object oriented way.  Useful for building small and mostly static tables such as forms, settings, menus, etc...  We prefer readability over memory efficiency, so it is not recommended to use this with tables that may have a large number of cells.",
    "homepage": "https://github.com/enriquez/MEDeclarativeTable",
    "screenshots": "http://i.imgur.com/ZENmO6l.png",
    "license": "MIT",
    "authors": {
        "Mike Enriquez": "[email protected]"
    },
    "source": {
        "git": "https://github.com/enriquez/MEDeclarativeTable.git",
        "tag": "0.3.0"
    },
    "social_media_url": "https://twitter.com/enriquez",
    "platforms": {
        "ios": "7.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "resource_bundles": {
        "MEDeclarativeTable": [
            "Pod/Assets/*.png"
        ]
    }
}

Pin It on Pinterest

Share This