代码拉取完成,页面将自动刷新
同步操作将从 陈海刚/CHGAdapter 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
主要解决UITableView 在每个controller中都需要设置dataSource和delegate的烦恼,并UITableViewCell与DataSource tableView解耦合 具体表现为
swift版: https://github.com/chenhaigang888/CHGAdapter_swift
pod 'CHGAdapter', '~> 0.2.2'
#import "ViewController.h"
#import "CHGTableViewAdapter.h"
@interface ViewController ()
@property(nonatomic,weak) IBOutlet UITableView * tableView;
@property(nonatomic,strong) CHGTableViewAdapter * adapter;
@property(nonatomic,strong) CHGTableViewAdapterData * adapterData;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.adapter.adapterData = self.adapterData;
self.tableView.tableViewAdapter = self.adapter;
[self.tableView setEmptyDataShowWithTitle:@"暂无数据" image:@"icon_dl_xsmm"];
self.tableView.eventTransmissionBlock = ^id(id target, id params, NSInteger tag, CHGCallBack callBack) {
return nil;
};
self.tableView.tableViewDidSelectRowBlock = ^(UITableView *tableView, NSIndexPath *indexPath, id itemData) {
NSLog(@"当前点击section:%li row:%li",indexPath.section,indexPath.row);
};
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
-(CHGTableViewAdapter*)adapter{
if (!_adapter) {
_adapter = [CHGTableViewAdapter new];
_adapter.cellName = @"SimpleTableViewCell";
_adapter.headerName = @"SampleTableViewHeaderFooterView";
_adapter.footerName = @"SampleTableViewHeaderFooterView";
_adapter.cellHeight = -1;
_adapter.headerHeight = 30;
_adapter.footerHeight = 44;
}
return _adapter;
}
-(CHGTableViewAdapterData*) adapterData {
if (!_adapterData) {
_adapterData = [CHGTableViewAdapterData new];
}
_adapterData.cellDatas = @[
@[@"1",@"2",@"3",@"4",@"5",@"6"],
@[@"1",@"2",@"3",@"4",@"5",@"6"]
];
_adapterData.headerDatas = @[@"第一个section的Header",@"第二个section的Header"];
_adapterData.footerDatas = @[@"第一个section的Footer",@"第二个section的Footer"];
return _adapterData;
}
@end
#import "CollectionViewViewController.h"
#import "TestCollectionAdapter.h"
#import "SampleLayout.h"
@interface CollectionViewViewController ()
@property(nonatomic,weak) IBOutlet UICollectionView * collectionView;
@property(nonatomic,strong) TestCollectionAdapter * adapter;
@property(nonatomic,strong) CHGCollectionViewAdapterData * adapterData;
@end
@implementation CollectionViewViewController
- (void)viewDidLoad {
[super viewDidLoad];
UICollectionViewFlowLayout * layout = [UICollectionViewFlowLayout new];
layout.itemSize = CGSizeMake(100, 100);
layout.headerReferenceSize = CGSizeMake(self.view.frame.size.width, 30);
layout.footerReferenceSize = CGSizeMake(self.view.frame.size.width, 30);
self.collectionView.collectionViewLayout = layout;
self.adapter.adapterData = self.adapterData;
self.collectionView.collectionViewAdapter = self.adapter;
[self.collectionView setEmptyDataShowWithTitle:@"没有任何数据" image:@"icon_dl_xsmm"];
self.collectionView.eventTransmissionBlock = ^id(id target, id params, NSInteger tag, CHGCallBack callBack) {
NSLog(@"paramsjjj:%@",params);
return nil;
};
self.collectionView.collectionViewDidSelectItemAtIndexPathBlock = ^(UICollectionView *collectionView, NSIndexPath *indexPath, id itemData) {
NSLog(@"itemData:%@",itemData);
};
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
-(TestCollectionAdapter*)adapter {
if (!_adapter) {
_adapter = [TestCollectionAdapter new];
_adapter.cellName = @"Sample1CollectionViewCell";
_adapter.sectionHeaderName = @"SampleHeaderCollectionReusableView";
_adapter.sectionFooterName = @"SampleHeaderCollectionReusableView";
_adapter.rowsOfSectionKeyName = @"test";
}
return _adapter;
}
-(CHGCollectionViewAdapterData*)adapterData {
if (!_adapterData) {
_adapterData = [CHGCollectionViewAdapterData new];
}
_adapterData.customData = [NSMutableDictionary dictionary];
_adapterData.cellDatas =
@[
@{@"test":@[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8"]},
@{@"test":@[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8"]}
];
_adapterData.headerDatas = @[@"h1",@"h2"];
_adapterData.footerDatas = @[@"f1",@"f2",@"f3",@"f4"];
return _adapterData;
}
@end
具体使用请参考Demo中的SimpleAdapterViewController页面
CHGTableViewAdapter和CHGCollectionViewAdapter默认实现一种类型的Cell和一种类型的HeaderView以及FooterView,如果你的TableView、CollectionView想显示不通风格的Cell、HeaderView、FooterView;可以通过集成CHGCollectionViewAdapter、CHGCollectionViewAdapter方式扩展。通过扩展实现以下几个方法返回不同类型,以及在Adapter的子类中实现TableView的DataSource、Delegate方法。CollectionView同理
/**
获取cell的类名
@param data indexPath的数据
@param tableView tableView对象
@param indexPath indexPath
@return 返回indexPath的cell 类名
*/
-(NSString*)obtainCellNameWithCellData:(id)data tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
/**
获取header的类名
@param data 当前header的数据
@param tableView tableView对象
@param section section
@return 返回section的类名
*/
-(NSString*)obtainHeaderNameWithHeaderData:(id)data tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
/**
获取footer的类名
@param data 当前footer的数据
@param tableView tableView对象
@param section section
@return 返回section的类名
*/
-(NSString*)obtainFooterNameWithFooterData:(id)data tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。