Code Monkey home page Code Monkey logo

tmswechat's Introduction

TMSWeChat

IGListKit实现微信朋友圈

IGListKit应该有人耳闻,它最大的特点便是基于数据驱动的这样一个特性,我使用它的动机也是鉴于它的这种类似“组装者”的理念,把同一组数据拆分成不同section,每个section维护着自己独立的单元格(cell)。 IGListKit实现朋友圈

先放一张搜索IGListKit都会出现的架构图,我也会围绕这个架构图来叙述我的实现方式

  • ViewController是一个包含CollectionView的容器,在这个VC中需要关联CollectionView和Adapter。
    [self.view addSubview:self.collectionView];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.view);
        make.top.equalTo(@([UIApplication sharedApplication].statusBarFrame.size.height+44));
    }];
    self.adapter.collectionView = self.collectionView;
    self.adapter.dataSource = self;
  • 在完成关联之后,接下来需要对每条数据进行拆分,我这里把一条数据拆分成了两个SectionController

评论区独立成为一个SectionController也是受上边那篇文章的启发,根据上边的那张IGListKit架构图,SectionController是包含cell的,如果让两个SectionController合并成一个SectionController,当评论数过多时,对于评论处cell的高度计算则显得尤为麻烦,因为这样做需要计算其整体高度,而将评论区拆分成独立的SectionController,我们需要计算的仅仅是每一条评论的高度,无需关心整个评论区的高度,而且这个高度也是每个SectionController需要实现的方法- (CGSize)sizeForItemAtIndex:(NSInteger)index;,形同于UITableView的- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;

  • 拆分完成后,使用cell“装填”每个SectionController

  • 最后再配合ViewModel去完成数据的展示

简书详情介绍

tmswechat's People

Contributors

tmmmmms avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.