CocoaPods trunk is moving to be read-only. Read more on the blog, there are 17 months to go.

SCTBDataSource 1.0.0

SCTBDataSource 1.0.0

Maintained by Samueler.



  • By
  • Samueler

SCTBDataSource

SCTBDataSource separates UITableView dataSource and delegate.It's not necessary to write some frequently dataSource and delegate functions again.You just focus on assemble datas and custom UITableViewCell.

Installation

CocoaPods

The easiest way of installing SCTBDataSource is via CocoaPods

pod 'SCTBDataSource'

Old-fashioned way

  1. Download SCTBDataSource project.
  2. Drag Core folder to your project.

Description

SCTBRowItem

SCTBRowItem contians a lot of necessary properties that create UITableViewCell.

@property (nonatomic, strong) id rowData;
@property (nonatomic, assign) CGFloat rowHeight;
@property (nonatomic, copy) NSString *cellClassString;

Notice:

You must set the class name of custom UITableViewCell for cellClassString property.If you don't set the property correctly,SCTBDataSource will create a UItableViewCell with system default style.

SCTBSectionItem

SCTBSectionItem is an object that describles UITableView some section informations.If your whole section's UITableViewCell is same, you can set YES to the property named rowItemIsSameOne.Then set correct value for sectionRowHeight and sectionCellClassString.

Notice:

sectionRowHeight and sectionCellClassString is invalid when rowItemIsSameOne value is NO.

SCTBDataSource

SCTBDataSource conforms UITableViewDataSource,and implements necessary protocol functions.You need pass a mutable array that contains SCTBSectionItem to the object,then it will create UITableViewCell with section item informations.

SCTBDelegate

SCTBDelegate conforms UITableViewDelegate, and implements some protocol functions.If you want to pass some events to super view, you can design blocks for specific protocol functions.

Usage

  1. Create SCTBDataSource and SCTBDelegate object like this:
NSMutableArray<SCTBRowItem *> *rowItems = [NSMutableArray array];
for (NSString *data in self.datas) {
    // system default style UITableViewCell
    SCTBRowItem *rowItem = [SCTBRowItem rowItemWithRowData:data];
    rowItem.rowHeight = 100.f;
    [rowItems addObject:rowItem];
}

SCTBSectionItem *sectionItem = [SCTBSectionItem sectionItemWithRowItems:rowItems];
NSMutableArray<SCTBSectionItem *> *sectionItems = [NSMutableArray array];
[sectionItems addObject:sectionItem];

if (!self.dataSource) {
    self.dataSource = [SCTBDataSource dataSourceWithSectionItems:sectionItems];
} else {
    self.dataSource.sectionItems = sectionItems;
}

if (!self.delegate) {
    self.delegate = [SCTBDelegate delegatWithSectionItems:sectionItems];
} else {
    self.delegate.sectionItems = sectionItems;
}

self.tableView.dataSource = self.dataSource;
self.tableView.delegate = self.delegate;

Notice:

If you create system default style UITableViewCell,you should create a category for UITableViewCell and conform the protocol namedSCTBDataSourceProtocol,then implementsetupTableViewCellWithRowData function when you want to set value for subViews.If you create a custom UITableViewCell,the custom cell should conform SCTBDataSourceProtocol and implement protocol function.

Other detail usage you can see the Example folder.

License

SCTBDataSource is licensed under the terms of the MIT License.