Latest 0.1.1
Homepage https://github.com/jeffnjut/FJTableView
License MIT
Platforms ios 7.0, requires ARC
Dependencies Masonry, BlocksKit, FJTool/Array
Authors

How To Get Started

FJTableView is a customized data-driven tableview.

Installation with CocoaPods

CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like FJTableView in your projects. See the Get Started section for more details.

Podfile

To integrate FJTableView into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'FJTableView'

Then, run the following command:

$ pod install

If any update occurs, run the following command:

$ pod update

Demo

Import

Import FJTableView Header File

#import <FJTableView/FJTableViewHeader.h>

Usage

Fast Involving FJTableView

FJTableView *tableView = [FJTableView createTableView:CGRectMake(0, 0, size.width, size.height) editStyle:0 seperatorStyle:0 backgroundColor:[UIColor whiteColor] tableViewBackgroundColor:nil configureBlock:nil];
[self.view addSubview:tableView];

Update config for FJTableView

tableView.editingStyle   = FJCellEditingStyleDeletionSwipe;
tableView.rowAnimation   = UITableViewRowAnimationFade;
tableView.seperatorStyle = UITableViewCellSeparatorStyleNone;
...... 
there're some other config params

Configure UI

self.configureBlock = ^(NSMutableArray *__strong *dataSource) {
NSMutableArray *_dataSource = *dataSource;
[_dataSource removeAllObjects];
if (weakSelf.enableSection) {

for (int section = 0; section < 3; section++) {
FJSectionObject *sectionObject = [[FJSectionObject alloc] init];

FeedsHeaderViewDataSource *feedHeadDataSource = [[FeedsHeaderViewDataSource alloc] init];
feedHeadDataSource.name = [NSString stringWithFormat:@"%d", section + 1];
sectionObject.headerViewDataSource = feedHeadDataSource;

for (int row = 0; row < 3; row++) {
FeedsCellDataSource *feedDataSource = [[FeedsCellDataSource alloc] init];
feedDataSource.name = [NSString stringWithFormat:@"%d", row + 1];
[sectionObject.cellDataSources append:feedDataSource];
}
[_dataSource append:sectionObject];
}

}else{

for (int row = 0; row < 10; row++) {
FeedsCellDataSource *feedDataSource = [[FeedsCellDataSource alloc] init];
feedDataSource.name = [NSString stringWithFormat:@"%d", row + 1];
[_dataSource append:feedDataSource];
}
}
};

Render UI

// If configureBlock was set,call [tableView refresh] directly!
// else
[tableView refresh:self.configureBlock];

Set Callback

configureBlock is preparing for FJTableView UI,
actionBlock is reacting for tapping, deleting, inserting on UITableViewCell or HeaderFooterView,
moveBlock is reacting for moving of UITableViewCell,
scrollBlock is dealing with scrolling action,
indexesBlock and indexBlock are for tableview index function

self.tableView.actionBlock = ^(FJTableView *tableView, FJActionBlockType type, NSInteger section, NSInteger row, __kindof id cellData, __kindof id cell) {
switch (type) {
case FJActionBlockTypeTapped:
{
if ([cellData isKindOfClass:[FJCellDataSource class]]) {
NSLog(@"Cell Tapped");
}else if ([cellData isKindOfClass:[FJViewDataSource class]]) {
NSLog(@"View Tapped");
}
break;
}

case FJActionBlockTypeCustomizedTapped:
{
if ([cellData isKindOfClass:[FeedsCellDataSource class]]) {
FeedsCellDataSource *_data = cellData;
if (_data.action == FeedsAction_Blue ) {
NSLog(@"Blue Button Tapped!!!");
}else if (_data.action == FeedsAction_Black) {
NSLog(@"Black Button Tapped!!!");
}else{
NSLog(@"Other Button On Cell Tapped!!!");
}

[cell extend:FJ_ExtenedType_Auto extendedBlock:^(BOOL beforeReload, BOOL extended) {
if (extended) {
NSLog(@"Cell Extend");
}else{
NSLog(@"Cell Collapse");
}
}];

}else if ([cellData isKindOfClass:[FeedsHeaderViewDataSource class]]) {
NSLog(@"Header View Tappeded");
[cell extend:FJ_ExtenedType_Auto extendedBlock:^(BOOL beforeReload, BOOL extended) {
if (extended) {
NSLog(@"View Extend");
}else{
NSLog(@"View Collapse");
}
}];
}
break;
}

case FJActionBlockTypeMultiSelected:
{
if ([cellData isKindOfClass:[FJCellDataSource class]]) {
FJCellDataSource *ds = cellData;
if (ds.multiSelected) {
NSLog(@"Multi Selected");
}else {
NSLog(@"Multi De-Selected");
}
}

break;
}

case FJActionBlockTypeDeleted:
{
NSLog(@"Deleted");
break;
}

case FJActionBlockTypeDeletedWConfirm:
{
NSLog(@"Deleted W Confirm");
FJAlertModel *alertModel = [FJAlertModel alertModel:@"删除" style:0 action:^{

[weakSelf.tableView refresh:^(NSMutableArray *__strong *dataSource) {
NSMutableArray *_dataSource = *dataSource;
[_dataSource remove:cellData];
}];

} color:[UIColor redColor]];
[weakSelf alertView:nil message:@"Sure for deletion?" cancel:YES cancelColor:[UIColor grayColor] item:alertModel, nil];
break;
}

case FJActionBlockTypeInserted:
{
NSLog(@"Inserted");
[weakSelf addCell:cellData];
break;
}
}
};

self.tableView.moveBlock = ^(FJTableView *tableView, NSIndexPath *fromIndex, NSIndexPath *toIndex, __kindof id fromCellData, __kindof id fromCell, __kindof id toCellData, __kindof id toCell) {
NSLog(@"Cell was moved from %@ to %@", fromIndex, toIndex);
};

self.tableView.scrollBlock = ^(UIScrollView *scrollView, FJScrollBlockType type, CGFloat height, BOOL willDecelerate) {
// NSLog(@"type = %d, height = %f", (int)type, height);
};

Detail

Make Cell

You could write UI in coding or xib, method "configure:" must be implemented if some cell data passed from TableView’s DataSource. And If transferring event from cell to controller, you must call "tap:" to notice controller that you have tapped some button or anything.In DataSource coding, there’s a key atrribute "cellHeight" which refers to the height of itself.

@interface FeedsCell : FJCell

@end

@interface FeedsCellDataSource : FJCellDataSource
@property (nonatomic, copy)   NSString    *name;
@property (nonatomic, copy)   NSString    *cover_url;
@property (nonatomic, assign) FeedsAction  action;

@end
@interface FeedsCell()

@property (nonatomic, weak) IBOutlet UIImageView *iv_feeds;
@property (nonatomic, weak) IBOutlet UILabel     *lb_name;
@property (nonatomic, weak) IBOutlet UIImageView *iv_extend;
@property (nonatomic, weak) IBOutlet UIView      *v_black;
@property (nonatomic, weak) IBOutlet UITextField *tf_cellHeight;
@property (nonatomic, weak) IBOutlet UIButton    *btn_refresh;

@end

@implementation FeedsCell

- (void)awakeFromNib {
// Initialization code
[super awakeFromNib];
self.iv_feeds.layer.masksToBounds = YES;

__weak typeof(self) weakSelf = self;
[self.v_black bk_whenTapped:^{
[weakSelf tap:^(__kindof FJCellDataSource *__strong *data) {
FeedsCellDataSource *_data = *data;
_data.action = FeedsAction_Black;
}];
}];

[self.btn_refresh bk_addEventHandler:^(id sender) {

[weakSelf reloadCell:^(__kindof FJCellDataSource *__strong *data) {

FeedsCellDataSource *_data = *data;
CGFloat h = [weakSelf.tf_cellHeight.text floatValue];
_data.height = h;

} animation:UITableViewRowAnimationFade];

} forControlEvents:UIControlEventTouchUpInside];

[self.btn_refresh setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[self.btn_refresh setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];

// Configure the view for the selected state
}

- (FJCell *)configure:(FJCellDataSource *)data {
__weak typeof(self) weakSelf = self;

return [self configure:data configureCellBlock:^(__kindof FJCellDataSource *data, __kindof FJCell *cell) {
FeedsCellDataSource *_data = data;
weakSelf.lb_name.text = _data.name;
weakSelf.iv_extend.image = [UIImage imageNamed:_data.name];
weakSelf.iv_feeds.image = [UIImage imageNamed:_data.name];
weakSelf.tf_cellHeight.text = [NSString stringWithFormat:@"%.1f",_data.height];
if (_data.extended) {
weakSelf.iv_extend.hidden = NO;
weakSelf.iv_extend.alpha = 0.0;
[UIView animateWithDuration:0.4 animations:^{
weakSelf.iv_extend.alpha = 1.0;
} completion:^(BOOL finished) {
weakSelf.iv_extend.alpha = 1.0;
}];
}else{
weakSelf.iv_extend.hidden = YES;
}
}];
}

- (IBAction)click:(id)sender {

[self tap:^(__kindof FJCellDataSource *__strong *data) {
FeedsCellDataSource *_data = *data;
_data.action = FeedsAction_Blue;
}];
}

@end

@implementation FeedsCellDataSource

- (instancetype)init
{
self = [super init];
if (self) {
self.tapEffect = FJCellTapEffectNone;
self.height = 200.0;
self.extendedHeight = 400.0;
self.supportDeletion = YES;
self.supportMoving = YES;
}
return self;
}

@end

Support Section

If section is enabled, section header and section footer is similar with cell style, but they inherited from FJView & FJViewDataSource, please refer to configure block in this sample.

for (int section = 0; section < 3; section++) {
FJSectionObject *sectionObject = [[FJSectionObject alloc] init];

FeedsHeaderViewDataSource *feedHeadDataSource = [[FeedsHeaderViewDataSource alloc] init];
feedHeadDataSource.name = [NSString stringWithFormat:@"%d", section + 1];
sectionObject.headerViewDataSource = feedHeadDataSource;

for (int row = 0; row < 3; row++) {
FeedsCellDataSource *feedDataSource = [[FeedsCellDataSource alloc] init];
feedDataSource.name = [NSString stringWithFormat:@"%d", row + 1];
[sectionObject.cellDataSources append:feedDataSource];
}
[_dataSource append:sectionObject];
}

Write MJRefresh with FJTableView seamlessly

[self.tableView tableView].mj_header = MJHeader Object ...
[self.tableView tableView].mj_footer = MJFooter Object ...

Contribute

Feel free to open an issue or pull request, if you need help or there is a bug.

Contact

Todo

  • Documentation

License

FJTableView is available under the MIT license. See the LICENSE file for more info.

The MIT License (MIT)

Copyright (c) 2017 Jeff

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Latest podspec

{
    "name": "FJTableView",
    "version": "0.1.1",
    "summary": "A Customized Data-driven Tableview",
    "homepage": "https://github.com/jeffnjut/FJTableView",
    "license": "MIT",
    "authors": {
        "jeff_njut": "[email protected]"
    },
    "platforms": {
        "ios": "7.0"
    },
    "source": {
        "git": "https://github.com/jeffnjut/FJTableView.git",
        "tag": "0.1.1"
    },
    "source_files": "FJTableView/Classes/**/*.{h,m}",
    "dependencies": {
        "Masonry": [],
        "BlocksKit": [],
        "FJTool/Array": []
    },
    "requires_arc": true
}

Pin It on Pinterest

Share This