Skip to content

nightwolf-chen/JDCHorizontalTableView

Repository files navigation

JDCHorizontalTableView

CI Status Version License Platform

Quick start

Create JDCHorizontalTableView as any other view and setup all the properties:

    self.tableView = [[JDCHorizontalTableView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 300)];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.backgroundColor = [UIColor whiteColor];

    [self.view addSubview:_tableView];
    _tableView.center = CGPointMake(screenWidth/2.0f,screenHeight/2.0f);

    [_tableView registerReuableCellClass:[JDCHorizontalTableCell class]
    reuabelIndentifier:kReuableIdentifier];

    UINib *nib = [UINib nibWithNibName:@"JDCCustomCell" bundle:[NSBundle mainBundle]];
    [_tableView registerReuableCellNib:nib
    reuabelIndentifier:kReuableIdentifier];
    [_tableView reloadData];

Just like UITableView. You just need setup delegate and data source first.

@interface JDCViewController : UIViewController<JDCHorizontalTableViewDataSource,JDCHorizontalTableViewDelegate>

@end

Implement the Datasource and Delegate methods

- (JDCHorizontalTableCell *)ps_tableView:(JDCHorizontalTableView *)tableView columForIndexPath:(NSUInteger)index
{
    JDCHorizontalTableCell *cell = [tableView dequeueReusableCellWithIdentifier:kReuableIdentifier];

    if (index % 2 == 0) {
    cell.backgroundColor = [UIColor orangeColor];
    }else{
    cell.backgroundColor = [UIColor greenColor];
    }

    return cell;
}

- (CGFloat)ps_tableViewWidthForColum:(JDCHorizontalTableView *)tableView colum:(NSUInteger)colum
{
    return 80;
}

- (NSUInteger)numberOfColums:(JDCHorizontalTableView *)tableView
{
    return 10;
}

You are ready to go!

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

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

pod "JDCHorizontalTableView"

Author

Jidong Chen, jidongchen93@gmail.com

License

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