nje

NJEasyTable

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

Showing:

Popularity

Downloads/wk

0

GitHub Stars

141

Maintenance

Last Commit

5yrs ago

Contributors

1

Package

Dependencies

0

License

MIT

Categories

Readme

NJEasyTable

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

install

use cocoapods

pod  'NJEasyTable'

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


Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100