博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
瘦身UITableViewController
阅读量:7026 次
发布时间:2019-06-28

本文共 1185 字,大约阅读时间需要 3 分钟。

如果我们用UITableViewController的话,一般情况下都会重复的在每个类里面写如下三个方法

#pragma mark UITableViewDataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    PGTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellReuseIdentifier];     return cell; } 复制代码

如果项目大的话,每个类都要写,写的很臃肿,很麻烦,那么有没有办法可以解决呢

答案就是PGBaseDataSource

PGBaseDataSource的写法

[[PGBaseDataSource instance] numberOfSectionsInTableView:^NSUInteger(UITableView *tableView) {
    return 1; } numberOfRowsInSection:^NSUInteger(UITableView *tableView, NSInteger section) {
    return 10; } cellForRowAtIndexPath:^UITableViewCell *(UITableView *tableView, NSIndexPath *indexPath) {
    PGTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellReuseIdentifier];     return cell; }]; 复制代码

Cocoapods安装

pod 'PGBaseDataSource'复制代码

PGBaseDataSource地址

https://github.com/xiaozhuxiong121/PGBaseDataSource复制代码

转载于:https://juejin.im/post/5a312ce56fb9a0452936c257

你可能感兴趣的文章
二分查找
查看>>
大嫂的HTML
查看>>
获取元素的宽高和位置(转自脚本之家)
查看>>
对于yum中没有的源的解决办法-EPEL
查看>>
web安全问题总结
查看>>
使用VMware 管理服务器
查看>>
初学 python 之 用户登录实现过程
查看>>
Spark性能调优
查看>>
BOS中控件非空 非0校验
查看>>
vue入门项目(vue + vuex + VueRouter + mint-ui)
查看>>
放弃FreeMark?
查看>>
《数据结构和算法分析》 练习题解答
查看>>
Java8 Lambda代码备份
查看>>
css伪元素实现tootip提示框
查看>>
Python基础知识随手记
查看>>
bzoj 1191 [HNOI2006]超级英雄Hero——二分图匹配
查看>>
关于xshell无法连接到centos的问题
查看>>
模块模式和单例模式的详解
查看>>
AMD和Intel的cpu架构的区别
查看>>
关于函数指针的总结
查看>>