Latest 1.0.0
Homepage https://github.com/HYPERCHEN/PBITableView
License MIT
Platforms ios 9.0
Frameworks UIKit
Authors

Artboard.png

language 
Carthage compatible 
Build Status 
License MIT 
Support

PBITableView is a kind of delightful tableview using MVVM.Compare the old ways, it provides a simply function to create the every single section, which makes creating complex tableview likes building blocks.What’s more, it is convenient to provides some cell styles for static view.Hope it could help the iOS developers.

Common View we need build

WechatIMG2.jpeg

This type of tableview has several feature:

  • regular cell style but includes different user interaction component like switch , textfield ,label and so on.
  • there are many similar views in different apps.
  • writing code for this view in a waste of time and energy.

Therefor we need to improve it.

The old ways to create

self.tableview.delegate   = self;
self.tableview.datasource = self;
//Delagte and DataSource func
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    return cell;
}

Obviously, in this way, we need realize so many these functions and it is annoying especially we just want to realize some simple tableviews.

The new ways to create

PBITableView uses this simple functions to create:


-(void)init{
    [self initTableView];
    [self addBaseSection];
}
-(void)addBaseSection{
    [self.tableView headerView:^(PBITableViewSectionModel *sectionModel){
        //Set HeaderView
    } withCells:^(NSMutableArray *cellArray) {
        //Set CellModel Arrays
        PBITableViewCellModel *cellModel = [PBITableViewCellModel new];
        cellModel.height = 50;
        cellModel.renderBlock=^UITableViewCell *(NSIndexPath *indexPath, UITableView *tableView) {
            //Init Cell Instance
            return cell;
            };
        }; 
        [cellArray addObject:cellModel];
    };
    } footerView:^(PBITableViewSectionModel *sectionModel){
        //Set footerView
    }];
}

Above all, it is the code about how to create a tableview with a section.All u need is realize the implementation of your cells and add the cellArray.U can set the appearance of section headerView and footerView By setting sectionModel properties.

I have written a demo in project.U can look up in detail.

The way to use manage style cells

PBIManageCell provides 5 styles cell.Each cells have their own styles too.Pick the style when init the cell.
For example, I would use the PBIMangeSwitchCell to express it.


    //Init Func pick style through PBIMangeSwitchCellStyle
    +(PBIMangeSwitchCell *)cellWithIdentifier:(NSString *)cellIdentifier tableView:(UITableView *)tableView style:(PBIMangeSwitchCellStyle)style;

    //Cell Instance Implementation 
    PBIMangeSwitchCell *cell = [PBIMangeSwitchCell cellWithIdentifier:@"123" tableView:tableView style:PBIMangeSwitchCellStyleWithLeftIcon];
            cell.titleLabel.text = @"Switch Change Cell Background";
            cell.leftIcon.image = [UIImage imageNamed:@"warning"];
            __weak __typeof__(PBIMangeSwitchCell *) weak_cell = cell;
            cell.switchBlock = ^(BOOL switchValue) {
                if (switchValue == YES) {
                    weak_cell.backgroundColor = [UIColor greenColor];
                }else{
                    weak_cell.backgroundColor = [UIColor yellowColor];
                }
            };

According to the different cells, it provides aimed properties and blocks to edit.

Warning Retain cycle

Because of the block usage, please notice the retain cycle problem.
u can use this __weak __typeof__(object) weak_object = object and __strong __typeof__(object) strong_object = object to avoid this problem

Code Structure

There are two main parts : PBIManageCell and PBITableView

PBIManageCell contains:

  • PBIManageCellConst.h
  • UIView+PBIManageLayout
  • PBIManageBaseCell.h
  • PBIMangeSwitchCell.h
  • PBIManageCustomCell.h
  • PBIManageLabelCell.h
  • PBIManageTextFieldCell.h

PBITableView contains:

  • PBITableView.h
  • PBITableViewModel.h
  • PBITableViewSectionModel.h
  • PBITableViewCellModel.h

Installation

#import PBIManageCell.h
#import PBITableView.h
//Then use the function in "The new ways to create" :)

License

PBITableView is released under the MIT license. See LICENSE for details.

Latest podspec

{
    "name": "PBIManageTableView",
    "version": "1.0.0",
    "summary": "A tableview constructed by MVVM and",
    "description": "A tableview constructed by MVVM and provides some styles for static/set/manage cell view.",
    "homepage": "https://github.com/HYPERCHEN/PBITableView",
    "license": "MIT",
    "authors": {
        "HYPERCHEN": "[email protected]"
    },
    "platforms": {
        "ios": "9.0"
    },
    "source": {
        "git": "https://github.com/HYPERCHEN/PBITableView.git",
        "tag": "1.0.0"
    },
    "source_files": "PBIManageTableView/**/*.{h,m}",
    "frameworks": "UIKit"
}

Pin It on Pinterest

Share This