瘦身UITableViewController

如果我们用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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,532评论 25 708
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,252评论 4 61
  • 有情不必终老,暗香浮动恰好,无情未必就是决绝,我只要你记着:初见时彼此的微笑…… 《人生若只如初见》...
    1703潘欣阅读 792评论 0 0
  • 最近流行各种“朦胧感”,找到点透明CSS属性记录一下。 透明往往能产生不错的网页视觉效果,先奉上兼容主流浏览器的C...
    sshsky阅读 310评论 0 2
  • 11号天兔,10.24 1.感谢同事在这个弥漫着桂花香气的夜里陪我散步谈心 2.感谢自己今天跟朋友表达了爸妈一辈子...
    小木棉oo阅读 289评论 0 0