Coder Social home page Coder Social logo

jvrbasetableviewdatasource's Introduction

##JVRBaseTableViewDataSource Build Status A basic, reusable and expandable UITableViewDataSource class, to take the clutter out of your UITableView classes. To use it, you will also need a class that conforms to the JVRCellConfiguratorDelegate, which will setup the individual cells, for the table view. For details about the usage, see the simple examples below, or refer to the example project.

Configuring Table View Cells

Cell configurator classes aim to encapsulate the logic that previously belonged in the tableView:cellForRowAtIndexPath: method found in the UITableViewDataSource protocol. They can be used to return the reuse identifier for a cell according to the object it is supposed to show, and to customize its appearance or behavior.

// MyCellConfigurator.h
#import "JVRBaseTableViewDataSource.h"

@interface MyCellConfigurator : NSObject<JVRCellConfiguratorDelegate>
@end

// MyCellConfigurator.m
@implementation MyCellConfigurator

- (NSString *)fetchCellIdentifierForObject:(id)anObject
{
    if ([anObject isKindOfClass:[MyClass class]])
    {
        return @"myCell";
    }

    return @"regularCell";
}

- (UITableViewCell *)configureCell:(MyCell *)cell usingObject:(MyClass *)object
{
    cell.titleLabel.text = object.stringProperty;
    return cell;
}

@end

Example usage in a Table View Controller:

By using JVRBaseTableViewDataSource, many lines of boilerplate code can be omitted from UITableViewController classes. Support for table view sections can be achieved by sublassing or editing this class, and implementing the numberOfSectionsInTableView: method.

// MyTableViewController.m
#import "JVRBaseTableViewDataSource.h"
#import "MyCellConfigurator.h"

@interface MyTableViewController ()

@property (nonatomic, strong) JVRBaseTableViewDataSource *dataSource;

@end

@implementation MyTableViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setupDataSource];
}

- (void)setupDataSource
{
    self.dataSource = [JVRBaseTableViewDatasource datasourceForTableView:self.tableView
                                                               withItems:@[@"test", @"item"]
                                                   usingCellConfigurator:[[MyCellConfigurator alloc] init]];
}

@end

Installation

You can just copy the source files into your project, but the recommended way of using this class in your project is installation through CocoaPods with the following Podfile:

platform :ios, "7.1"

pod 'JVRBaseTableViewDataSource'

jvrbasetableviewdatasource's People

Contributors

jozsef-vesza avatar

Stargazers

Sencho Kong avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.