Git Product home page Git Product logo

mcollectionview's Introduction

MCollectionView

UICollectionView的封装:

  1. 自动计算行高,缓存行高
  2. 支持设置cell的上下左右间隙
  3. 控制器减负最有效处理,根治MVC问题。不用写数据源方法,cell的点击事件逻辑分离到各cell中,逻辑清晰,代码不臃肿,代码复用耦合性少。
  4. 在cell中编写事件处理逻辑,可以直接获取CollectionView对象和ViewController对象,不用担心循环引用问题。消除一层层的代理传递,和通知传递数据

使用方法:

  1. 初始化:
MCollectionView *collectionView = [[MCollectionView alloc] initWithScrollDirection:UICollectionViewScrollDirectionVertical delegate:nil];
[self.view addSubview:collectionView];
  1. cell中实现- (void)setModel_mc:(NSObject *)model方法设置cell数据

  2. model中:实现- (NSString *)reuseViewName_mc方法,返回cell的类名

  3. 数据源:

MCollectionViewSectionModel *section1 = [MCollectionViewSectionModel new]; 
section1.itemModels = 第一组模型
section2.itemModels = 第二组模型
section3.itemModels = 第三组模型
NSMutableArray *sectionModels = [NSMutableArray arrayWithArray:@[section1, section2, section3]];
self.sectionModels = sectionModels;

完成!下面这些方法都不用写哦,控制器从此轻松了!:

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout

注:- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath方法也不用写,点击Cell的处理逻辑就写在Cell中。此库会调用Cell的didSelectItem_mc方法,并随后响应mDelegate的didSelectItemAtIndexPath代理方法

mcollectionview's People

Contributors

wejua avatar

Stargazers

 avatar

Watchers

 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.