IOS之UITableView实现Section独立封装
来源:互联网 发布:ipa下载不了软件 编辑:程序博客网 时间:2024/06/11 09:51
IOS之UITableView实现Section独立封装
WHY
IOS的UITableView组件,在复杂的场景下,经常会使用多个Section,每个Section都可能有不同的header/cell/footer。如果想对Section的逻辑进行封装,因为delegate和dataSource只能指向单独的实例上,并不是很方便,需要编写一些额外的代码,来分派UITableView的事件。所以完善了上一篇bolg(IOS 实现delegate链/广播的例子),来简化这一工作。
WHAT
CYMTableViewSection @github扩展了UITableView,提供将SectionID对应的事件独立处理的能力。使用此扩展,将很容易对业务层的Section逻辑进行封装。
HOW
以下例子介绍如何使用CYMTableViewSection
实现两个Section(MySection1和MySection2)
/** 测试section1*/@interface MySection1 : CYMTableViewSection<UITableViewDataSource> //只需继承自CYMTableViewSection@end@implementation MySection1-(instancetype)init{ self = [super init]; if (self) { self.dataSource = self; } return self;}//处理UITableViewDataSource事件//只会收到本Section实例对应的SectionId的事件- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *cellId = @"cellId"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: cellId]; } cell.textLabel.text = [NSString stringWithFormat:@"MySection1 | row %ld",(long)indexPath.row]; return cell;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 3;}@end// 类似方式实现MySection2...
加入UITableView
#import "UITableView+CYMSectionAdditions.h"@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; //创建两个Section加入tableview MySection1* sec1 = [[MySection1 alloc]init]; MySection2* sec2 = [[MySection2 alloc]init]; [_tabView addSection:sec1 reload:NO]; [_tabView addSection:sec2 reload:NO];}
运行,查看结果
依赖
本扩展依赖CYMDelegateChain
0 0
- IOS之UITableView实现Section独立封装
- IOS UITableView Section下拉列表实现
- IOS开发(28)UITableView之移动Section和Cell
- iOS UITableView设置Section间距
- ios uitableview 刷新某一个cell 或 section
- ios uitableview 刷新某一个cell 或 section
- ios uitableview 刷新某一个cell 或 section
- iOS-UITableView使用reloadSections刷新section问题
- iOS UITableView 刷新某一个cell 或 section
- ios UITableview 刷新某一个cell 或 section
- iOS 刷新 UITableView某个 section 或 cell
- iOS UITableView的Section Footer添加按钮
- ios UITableview 刷新某一个cell 或 section
- ios UITableview 刷新某一个cell 或 section
- ios UITableview 刷新某一个cell 或 section
- UITableview刷新cell或section iOS
- ios UITableview 刷新某一个cell 或 section
- ios uitableview 刷新某一个cell 或 section
- Linux with HDMI video output on the ZED, ZC702 and ZC706 boards
- xmemcached 客户端使用
- iOS运行原理笔记 by STP
- MATLAB使用频率方法的运动检测
- BaseAdapter-ListView中的item显示多种布局
- IOS之UITableView实现Section独立封装
- android gradle 配置
- Support Vector Machine
- Ubuntu查看内核版本和发行版本
- netstat和telnet命令在Windows7中的用法
- Win32 API(一)
- 【JVM系列】Java对象的生命周期与类型的卸载
- 物理内存分配与回收(5)之交换机制
- Java NIO使用及原理分析 (四)