Latest 1.0.1
Homepage https://github.com/NianJi/NJEasyTable
License MIT
Platforms ios 6.0, requires ARC
Frameworks Foundation, UIKit
Authors

A plugin of UITableView can easy manage models and auto calculate cell height with autolayout

Usage

#import "UITableView+NJEasyTable.h"

Set up models

You can add sections and rows to nj_TableModel.

[self.tableView.nj_TableModel addSection:({
        NJEasyTableSection *section = [[NJEasyTableSection alloc] initWithModel:nil];
        [section addRow:({
            NJEasyTableRow *row = [[NJEasyTableRow alloc] initWithModel:model];
            row.cellHeight = 44;
            row;
        })];
        section;
})];

Get models in dataSource and delegate method of UITableView

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [tableView.nj_TableModel numberOfSections];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [tableView.nj_TableModel numberOfRowsInSection:section];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cellIdentifier";
    TestCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[TestCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    id model = [tableView.nj_TableModel modelAtIndexPath:indexPath];
    [cell configWithModel:model];

    return cell;
}

Dynamic cell heights

If you use autolayout in UITableViewCell. you doesn’t need to calculate cell height manually.
Cell height value can like this:

// regist a cell for calculate cell height
TestCell *cell = [[TestCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
[self.tableView nj_registAutolayoutCell:cell forAutomaticCalculationHeightIdentifier:@"testCell"];

// implement in heightForRow
- (GFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    CGFloat height = [tableView nj_intrinsicHeightAtIndexPath:indexPath
                                                forIdentifier:@"testCell"
                                              configCellBlock:^(TestCell *cell, id model) {
                                                  [cell configWithModel:model];
                                              }];
    return height;
}

Latest podspec

{
    "name": "NJEasyTable",
    "version": "1.0.1",
    "summary": "Manage Datasource of UITableView",
    "description": "help UITableView to manage datasn* Easy Manage Data Model of TableViewn* Easy calculate and cache cell height",
    "platforms": {
        "ios": "6.0"
    },
    "homepage": "https://github.com/NianJi/NJEasyTable",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "u5ff5u7eaa": "[email protected]"
    },
    "source": {
        "git": "https://github.com/NianJi/NJEasyTable.git",
        "tag": "1.0.1"
    },
    "source_files": "sources/**/*.{h,m}",
    "requires_arc": true,
    "frameworks": [
        "Foundation",
        "UIKit"
    ]
}

Pin It on Pinterest

Share This