XTTable

by Akateason

Akateason / XTTable

A tool for quickly laying out and configuring UITable and UICollectionView

209 Stars 40 Forks Last release: Not found MIT License 25 Commits 2 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

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        // for UITableView and UITableViewCell
#import   // 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 { MyCell *cell = [MyCell xt_fetchFromTable:tableView] ; [cell xt_configure:self.list[indexPath.row] indexPath:indexPath] ; return cell; }

#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.

    We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.