Coder Social home page Coder Social logo

xttable's Introduction

XTTable

A tool for quickly laying out and configuring UITable and UICollectionView

Example

To run the example project, clone the repo, and run directory.

Requirements

iOS 8.0 or later

Installation

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

pod "XTTable"

Useage

#import <XTTable/XTTable.h>       // for UITableView and UITableViewCell
#import <XTTable/XTCollection.h>  // for UICollectionView and UICollectionViewCell

setup

    [MyCell xt_registerNibFromTable:self.table] ;
    [self.table xt_setup] ;

    self.table.delegate = self ;
    self.table.dataSource = self ;
    self.table.xt_Delegate = self ;

datasource and delegate

#pragma mark --
#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.list.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [MyCell xt_fetchFromTable:tableView] ;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    [cell xt_configure:self.list[indexPath.row] indexPath:indexPath] ;
}


#pragma mark --
#pragma mark - UITableViewDelegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [MyCell xt_cellHeightForModel:self.list[indexPath.row]] ;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    MyObj *obj = self.list[indexPath.row] ;
    NSLog(@"current index path %@, height %@",obj.name, @(obj.height)) ;
}

Reloader

#pragma mark --
#pragma mark - UITableViewXTReloaderDelegate

- (void)tableView:(UITableView *)table loadNew:(void (^)(void))endRefresh {
    // do load new ...
    endRefresh() ;
}

- (void)tableView:(UITableView *)table loadMore:(void (^)(void))endRefresh {
    // do load more ...
    endRefresh() ;
}

Cell configure

@implementation MyCell

- (void)xt_configure:(id)model indexPath:(NSIndexPath *)indexPath {
    [super xt_configure:model indexPath:indexPath] ;

    MyObj *myObj         = (MyObj *)model;
    _lbTitle.text  = myObj.name;
    _lbHeight.text = [NSString stringWithFormat:@"my Height is : %@", @(myObj.height)];
    self.backgroundColor = indexPath.row % 2 ? [UIColor greenColor] : [UIColor brownColor];
}

+ (CGFloat)xt_cellHeightForModel:(id)model {
    return ((MyObj *)model).height;
}

@end

pic

Author

teason, [email protected]

License

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

xttable's People

Contributors

akateason avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

xttable's Issues

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.