GokoTableView
轻松使用 tableview 的方法
如何开始
- 下载GokoTableViewDemo 并尝试其中的示例演示
安装
从 CocoaPods 构建
- CocoaPods 是 Objective-C 的依赖项管理器,它可以自动化和简化在项目中使用第三方库(如 GokoTableView)的过程。首先,将以下行添加到您的 Podfile
pod 'GokoTableView'
- 如果您想使用 GokoTableView 的最新功能,请使用标准的第三方依赖。
pod 'GokoTableView', :git => 'https://github.com/Gokotx/GokoTableView.git'
这将从主分支直接获取。
- 然后,将 GokoTableView 安装到您的项目中。
pod install
Carthage
- 目前不支持。即将推出。
手动
- 只需将
UITableView+Goko
文件夹拖入您的项目中。
使用方法
- 第一步
import "UITableView+Goko.h"
- 现在所有 UITableViewDelegate 和 UITableViewDataSource 方法都支持使用 Block 来实现。如下所示(
注意:代理和数据源自动绑定到 TableView 上,不要再绑定到某个 ViewController 上
)
...
[tableView setGoko_numberOfSectionsInTableView:^NSInteger{
return 1;
}]
[tableView setGoko_numberOfRowsInSection:^NSInteger(NSInteger section) {
@strongify(self);
return self.dataArray.count;
}];
[tableView setGoko_cellForRowAtIndexPath:^UITableViewCell *(NSIndexPath *indexPath) {
@strongify(tableView);
@strongify(self);
DemoModel * model = self.dataArray[indexPath.row];
NSString * cellReuseId = model.goko_cellReuseId;
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellReuseId];;
if (nil == cell) {
Class cellClass = model.goko_cellClass;
cell = [[cellClass alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellReuseId];
}
return cell;
}];
[tableView setGoko_willDisplayCell:^(UITableViewCell *cell, NSIndexPath *indexPath) {
@strongify(self);
DemoModel * model = self.dataArray[indexPath.row];
[cell setGoko_bindingData:model];
}];
...
- 您也可以使用以下方法初始化 tableview,以方便使用(详情请查看示例)
/**
Initial TableView
@param frame :TableView Frame
@param tableViewstyle style
@param separatorStyle style
@return TableView
*/
+ (instancetype)gokoTableViewWithFrame:(CGRect)frame
tableViewStyle:(UITableViewStyle)tableViewstyle
separatorStyle:(UITableViewCellSeparatorStyle)separatorStyle;
- 如果您使用上述方法初始化了 TableView,现在您可以轻松地插入或删除行
/**
Insert Rows without attention to dataSource
@param rowDatas : Rows bingding data
@param indexPaths : indexPath
@param rowAnimation : add animation
*/
- (void)gokoInsertRows:(NSArray<NSObject *> *)rowDatas
atIndexPaths:(NSArray<NSIndexPath *> *)indexPaths
withRowAnimation:(UITableViewRowAnimation)rowAnimation;
/**
Delete Rows without attention to dataSource
@param indexPaths : indexPath
@param animation : delete animation
*/
- (void)gokoDeleteRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths
withRowAnimation:(UITableViewRowAnimation)animation;
许可证
GokoTableView
在 MIT 许可下发布。详情请参阅 LICENSE。