测试已测试 | ✗ |
语语言 | Obj-CObjective C |
许可证 | MIT |
发布最后发布 | 2017年8月 |
由 jeff_njut 维护。
依赖 | |
Masonry | >= 0 |
BlocksKit | >= 0 |
FJTool/Array | >= 0 |
FJTableView 是一个自定义的数据驱动表格视图。
要使用 CocoaPods 将 FJTableView 集成到您的 Xcode 项目中,请在您的 Podfile
中指定它
pod 'FJTableView'
然后,运行以下命令
$ pod install
如果有任何更新,请运行以下命令
$ pod update
导入 FJTableView 头文件
#import <FJTableView/FJTableViewHeader.h>
FJTableView *tableView = [FJTableView createTableView:CGRectMake(0, 0, size.width, size.height) editStyle:0 seperatorStyle:0 backgroundColor:[UIColor whiteColor] tableViewBackgroundColor:nil configureBlock:nil];
[self.view addSubview:tableView];
tableView.editingStyle = FJCellEditingStyleDeletionSwipe;
tableView.rowAnimation = UITableViewRowAnimationFade;
tableView.seperatorStyle = UITableViewCellSeparatorStyleNone;
......
there're some other config params
self.configureBlock = ^(NSMutableArray *__strong *dataSource) {
NSMutableArray *_dataSource = *dataSource;
[_dataSource removeAllObjects];
if (weakSelf.enableSection) {
for (int section = 0; section < 3; section++) {
FJSectionObject *sectionObject = [[FJSectionObject alloc] init];
FeedsHeaderViewDataSource *feedHeadDataSource = [[FeedsHeaderViewDataSource alloc] init];
feedHeadDataSource.name = [NSString stringWithFormat:@"%d", section + 1];
sectionObject.headerViewDataSource = feedHeadDataSource;
for (int row = 0; row < 3; row++) {
FeedsCellDataSource *feedDataSource = [[FeedsCellDataSource alloc] init];
feedDataSource.name = [NSString stringWithFormat:@"%d", row + 1];
[sectionObject.cellDataSources append:feedDataSource];
}
[_dataSource append:sectionObject];
}
}else{
for (int row = 0; row < 10; row++) {
FeedsCellDataSource *feedDataSource = [[FeedsCellDataSource alloc] init];
feedDataSource.name = [NSString stringWithFormat:@"%d", row + 1];
[_dataSource append:feedDataSource];
}
}
};
// If configureBlock was set,call [tableView refresh] directly!
// else
[tableView refresh:self.configureBlock];
configureBlock 正在为 FJTableView UI 准备,actionBlock 用于单元格或 HeaderFooterView 上的点击、删除、插入操作,moveBlock 用于单元格的移动操作,scrollBlock 用于处理滚动操作,indexesBlock 和 indexBlock 用于表格索引功能
self.tableView.actionBlock = ^(FJTableView *tableView, FJActionBlockType type, NSInteger section, NSInteger row, __kindof id cellData, __kindof id cell) {
switch (type) {
case FJActionBlockTypeTapped:
{
if ([cellData isKindOfClass:[FJCellDataSource class]]) {
NSLog(@"Cell Tapped");
}else if ([cellData isKindOfClass:[FJViewDataSource class]]) {
NSLog(@"View Tapped");
}
break;
}
case FJActionBlockTypeCustomizedTapped:
{
if ([cellData isKindOfClass:[FeedsCellDataSource class]]) {
FeedsCellDataSource *_data = cellData;
if (_data.action == FeedsAction_Blue ) {
NSLog(@"Blue Button Tapped!!!");
}else if (_data.action == FeedsAction_Black) {
NSLog(@"Black Button Tapped!!!");
}else{
NSLog(@"Other Button On Cell Tapped!!!");
}
[cell extend:FJ_ExtenedType_Auto extendedBlock:^(BOOL beforeReload, BOOL extended) {
if (extended) {
NSLog(@"Cell Extend");
}else{
NSLog(@"Cell Collapse");
}
}];
}else if ([cellData isKindOfClass:[FeedsHeaderViewDataSource class]]) {
NSLog(@"Header View Tappeded");
[cell extend:FJ_ExtenedType_Auto extendedBlock:^(BOOL beforeReload, BOOL extended) {
if (extended) {
NSLog(@"View Extend");
}else{
NSLog(@"View Collapse");
}
}];
}
break;
}
case FJActionBlockTypeMultiSelected:
{
if ([cellData isKindOfClass:[FJCellDataSource class]]) {
FJCellDataSource *ds = cellData;
if (ds.multiSelected) {
NSLog(@"Multi Selected");
}else {
NSLog(@"Multi De-Selected");
}
}
break;
}
case FJActionBlockTypeDeleted:
{
NSLog(@"Deleted");
break;
}
case FJActionBlockTypeDeletedWConfirm:
{
NSLog(@"Deleted W Confirm");
FJAlertModel *alertModel = [FJAlertModel alertModel:@"删除" style:0 action:^{
[weakSelf.tableView refresh:^(NSMutableArray *__strong *dataSource) {
NSMutableArray *_dataSource = *dataSource;
[_dataSource remove:cellData];
}];
} color:[UIColor redColor]];
[weakSelf alertView:nil message:@"Sure for deletion?" cancel:YES cancelColor:[UIColor grayColor] item:alertModel, nil];
break;
}
case FJActionBlockTypeInserted:
{
NSLog(@"Inserted");
[weakSelf addCell:cellData];
break;
}
}
};
self.tableView.moveBlock = ^(FJTableView *tableView, NSIndexPath *fromIndex, NSIndexPath *toIndex, __kindof id fromCellData, __kindof id fromCell, __kindof id toCellData, __kindof id toCell) {
NSLog(@"Cell was moved from %@ to %@", fromIndex, toIndex);
};
self.tableView.scrollBlock = ^(UIScrollView *scrollView, FJScrollBlockType type, CGFloat height, BOOL willDecelerate) {
// NSLog(@"type = %d, height = %f", (int)type, height);
};
您可以在代码中编写 UI 或 XIB,如果单元格数据从表格的 DataSource 传递,则必须实现方法 "configure:"。并且如果从单元格传输事件到控制器,您必须调用 "tap:" 以通知控制器已点击某个按钮或其他内容。在 DataSource 编码中,有一个键属性 "cellHeight",它指向它自身的高度。
@interface FeedsCell : FJCell
@end
@interface FeedsCellDataSource : FJCellDataSource
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *cover_url;
@property (nonatomic, assign) FeedsAction action;
@end
@interface FeedsCell()
@property (nonatomic, weak) IBOutlet UIImageView *iv_feeds;
@property (nonatomic, weak) IBOutlet UILabel *lb_name;
@property (nonatomic, weak) IBOutlet UIImageView *iv_extend;
@property (nonatomic, weak) IBOutlet UIView *v_black;
@property (nonatomic, weak) IBOutlet UITextField *tf_cellHeight;
@property (nonatomic, weak) IBOutlet UIButton *btn_refresh;
@end
@implementation FeedsCell
- (void)awakeFromNib {
// Initialization code
[super awakeFromNib];
self.iv_feeds.layer.masksToBounds = YES;
__weak typeof(self) weakSelf = self;
[self.v_black bk_whenTapped:^{
[weakSelf tap:^(__kindof FJCellDataSource *__strong *data) {
FeedsCellDataSource *_data = *data;
_data.action = FeedsAction_Black;
}];
}];
[self.btn_refresh bk_addEventHandler:^(id sender) {
[weakSelf reloadCell:^(__kindof FJCellDataSource *__strong *data) {
FeedsCellDataSource *_data = *data;
CGFloat h = [weakSelf.tf_cellHeight.text floatValue];
_data.height = h;
} animation:UITableViewRowAnimationFade];
} forControlEvents:UIControlEventTouchUpInside];
[self.btn_refresh setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[self.btn_refresh setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (FJCell *)configure:(FJCellDataSource *)data {
__weak typeof(self) weakSelf = self;
return [self configure:data configureCellBlock:^(__kindof FJCellDataSource *data, __kindof FJCell *cell) {
FeedsCellDataSource *_data = data;
weakSelf.lb_name.text = _data.name;
weakSelf.iv_extend.image = [UIImage imageNamed:_data.name];
weakSelf.iv_feeds.image = [UIImage imageNamed:_data.name];
weakSelf.tf_cellHeight.text = [NSString stringWithFormat:@"%.1f",_data.height];
if (_data.extended) {
weakSelf.iv_extend.hidden = NO;
weakSelf.iv_extend.alpha = 0.0;
[UIView animateWithDuration:0.4 animations:^{
weakSelf.iv_extend.alpha = 1.0;
} completion:^(BOOL finished) {
weakSelf.iv_extend.alpha = 1.0;
}];
}else{
weakSelf.iv_extend.hidden = YES;
}
}];
}
- (IBAction)click:(id)sender {
[self tap:^(__kindof FJCellDataSource *__strong *data) {
FeedsCellDataSource *_data = *data;
_data.action = FeedsAction_Blue;
}];
}
@end
@implementation FeedsCellDataSource
- (instancetype)init
{
self = [super init];
if (self) {
self.tapEffect = FJCellTapEffectNone;
self.height = 200.0;
self.extendedHeight = 400.0;
self.supportDeletion = YES;
self.supportMoving = YES;
}
return self;
}
@end
如果启用了分区,分区头部和分区尾部与单元格样式类似,但它们继承自 FJView & FJViewDataSource,请参阅此示例中的配置块。
for (int section = 0; section < 3; section++) {
FJSectionObject *sectionObject = [[FJSectionObject alloc] init];
FeedsHeaderViewDataSource *feedHeadDataSource = [[FeedsHeaderViewDataSource alloc] init];
feedHeadDataSource.name = [NSString stringWithFormat:@"%d", section + 1];
sectionObject.headerViewDataSource = feedHeadDataSource;
for (int row = 0; row < 3; row++) {
FeedsCellDataSource *feedDataSource = [[FeedsCellDataSource alloc] init];
feedDataSource.name = [NSString stringWithFormat:@"%d", row + 1];
[sectionObject.cellDataSources append:feedDataSource];
}
[_dataSource append:sectionObject];
}
[self.tableView tableView].mj_header = MJHeader Object ...
[self.tableView tableView].mj_footer = MJFooter Object ...
如有需要帮助或发现bug,请随意打开issue或pull request。
FJTableView遵循MIT许可。有关更多信息,请参阅LICENSE文件。
MIT许可证 (MIT)
版权所有(c)2017 Jeff
在此特此授予任何人免费获得本软件及其相关文档副本(“软件”)的副本的权利,可以在不受限制的情况下处理软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件的副本,并允许获得软件的人这样做,但受以下条件约束:
上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。
软件按“原样”提供,不提供任何种类的任何保证,明示或暗示,包括但不限于适销性、特定用途适用性和非侵权性保证。在任何情况下,作者或版权持有人不对任何索赔、损害或其他责任承担责任,无论是由合同、侵权或任何其他行为引起的,不得在任何情况下,无论是在软件的使用过程中、出于使用软件本身或与之相关时发生。