UITableView 是 iOS 開發(fā)中最常用的控件之一馒索,我們對其進行模塊抽象化莹妒,使其用起來更加方便,簡單绰上。
Demo示例:CHTableView
一旨怠、用法簡介
1、引入 demo 中的 CHTableView 文件夾及其中所有類
2蜈块、導入 "CHCommonTableData.h"鉴腻,"CHCommonTableDelegate.h",
3百揭、聲明 @property (nonatomic ,strong) CHCommonTableDelegate *delegator;
4爽哎、viewDidLoad 調(diào)用
[self buildData];
// --必須寫在給 CHTableView 的 delegate 和 dataSource 賦值之前
__weak typeof (self) weakSelf = self; // - block塊,防止循環(huán)引用
self.delegator = [[CHCommonTableDelegate alloc] initWithTableData:^NSArray *{
return weakSelf.data;
}];
// --創(chuàng)建初始化tableview
self.CHTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
self.CHTableView.backgroundColor = [UIColor whiteColor];
self.CHTableView.delegate = self.delegator;
self.CHTableView.dataSource = self.delegator;
self.CHTableView.tableFooterView = [[UIView alloc] init]; // - 不顯示空白cell
[self.view addSubview:self.CHTableView];
5器一、buildData 方法
NSArray *data = @[
@{
HeaderTitle:@"",
HeaderHeight:@(20),
RowContent :@[
@{
Title : @"個人簡介",
ExtraInfo : @"136********",
CellClass : @"CHTestTableViewCell",
RowHeight : @(100),
CellAction : @"onTouchPortrait:",
ShowAccessory : @(YES)
},
],
FooterTitle:@"",
FooterHeight:@(20)
},
@{
HeaderTitle:@"",
HeaderHeight:@(20),
RowContent :@[
@{
Title :@"昵稱",
DetailTitle:@"HaoTime",
CellAction :@"onTouchNickSetting:",
RowHeight : @(50),
ShowAccessory : @(YES),
},
@{
Title :@"性別",
DetailTitle:@"男",
CellAction :@"onTouchGenderSetting:",
RowHeight : @(50),
ShowAccessory : @(YES)
},
@{
Title :@"生日",
DetailTitle:@"保密",
CellAction :@"onTouchBirthSetting:",
RowHeight : @(50),
ShowAccessory : @(YES)
},
@{
Title :@"手機",
DetailTitle:@"136********",
CellAction :@"onTouchTelSetting:",
RowHeight : @(50),
ShowAccessory : @(YES)
},
@{
Title :@"郵箱",
DetailTitle:@"124****587@qq.com",
CellAction :@"onTouchEmailSetting:",
RowHeight : @(50),
ShowAccessory : @(YES)
},
@{
Title :@"簽名",
DetailTitle:@"哎呦不錯哦",
CellAction :@"onTouchSignSetting:",
RowHeight : @(50),
ShowAccessory : @(YES)
},
],
FooterTitle:@"",
FooterHeight:@(20)
},
];
self.data = [CHCommonTableSection sectionsWithData:data];