首页 技术 正文
技术 2022年11月9日
0 收藏 487 点赞 4,847 浏览 1560 个字

前言:阅读了《更轻量的 View Controllers》,发现笔者这个优化重构代码的想法真的很不错,可以使得抽取的UITableViewDataSource独立写在一个类文件里,并且也写出了了自定义UITableViewCell绑定相关的xib,然后在类别拓展这个UITableViewCell然后赋值。抽取UITableViewDataSource的亮点就是将过程”用model的属性设置cell”通过block来写入并进行了传值。

但是小编自己想进一步封装,想达到这个UITableViewDataSource类,能够达到完全独立和封装,提供一个方便用的接口来使用。

但是没有成功,还是留给以后捣鼓捣鼓吧,对应《更轻量的 View Controllers》的github下载地址:github上的示例程序。

下面是我自己的简要分析过程,试图将UITableViewDataSource进行抽取封装:

UITableViewDataSource任务执行的过程首先将UIViewController对象设置为 UITableView对象的 数据源    self.tableView.dataSource = self;或者将UITableView的子类本身设置为 自己的 数据源    self.dataSource = self;然后实现数据源协议的方法#pragma mark - UITableViewDataSource协议方法- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return self.visibleCellRows.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSArray* arr = self.visibleCellRows[section];
return arr.count;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
return @"Hello";
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:self.cellIdentifier
forIndexPath:indexPath];
id item = [self itemAtIndexPath:indexPath];
self.configureCellBlock(cell, item);
return cell;
}但是:
要先拿到模型对象
因为:
要用到模型对象的count 模型对象的一些数据:
UITableViewCell的创建和设置,绑定ID的形式
对于二维模型数组,先要获得section的title,section的高数据源内部的方法:
可以到apple内部头文件查看==================================================而封装的需求:
参数:、模型数组 、cell的ID 、
业务:、用模型属性为cell的属性进行赋值===================================================
文章:http://www.objccn.io/issue-1/
中是将业务1的逻辑步骤 写在自定义cell的类别中
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,495
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,909
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,741
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,496
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,134
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,298