DFITableViewManager 0.1.1

DFITableViewManager 0.1.1

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最新版本2016年11月

sdaheng维护。



  • sdaheng

DFITableViewManager 是为 UITableView 提供的驱动数据内容管理器。使您能够轻松管理 UITableView 的内容,无论是列表还是表格。

用法

DFITableViewConfiguration *tableViewConfiguration =
[DFITableViewConfiguration configureTableView:self.tableView withRowIsSameInSection:nil];

tableViewConfiguration.registerClassCells = @{@"cell" : [DemoCustomCell class]};

self.dataSource = @[[@[ @"CodeDemo", @"DataFormatDemo", @"PlistDemo" ] map:^id(id value) {
    return [[DemoCustomCellViewModel alloc] initWithText:value];
}]];

// select row
// tableViewDelegate
tableViewConfiguration.tableViewDelegate = self;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
    [self selectCellAtIndexPath:indexPath];
}
// ReactiveCocoa
@weakify(self)
[tableViewConfiguration.selectRowSignal subscribeNext:^(RACTuple * x) {
     @strongify(self)
     NSIndexPath *indexPath = [x second];

     [self selectCellAtIndexPath:indexPath];
 }];

自定义单元格

@interface DemoCustomCell : UITableViewCell

@end

@interface DemoCustomCell () <UITableViewCellConfigureProtocol>

@end

@implementation DemoCustomCell

- (void)configureCellWithInfo:(id)info
                       option:(NSDictionary * _Nullable)option {
    self.textLabel.text = ((DemoCustomCellViewModel *)info).text;
}

@end

// CellViewModel
@interface DemoCustomCellViewModel

@property(nonatomic, copy) NSString *text;

@end

@implementation DemoCustomCellViewModel

- (instancetype)initWithText:(NSString *)text {
    DFITableViewCellConfigure *tableViewCellConfigure =
    [[DFITableViewCellConfigure alloc] initWithReuseIdentifier:@"cell"];
    self = [super initWithCellConfigure:tableViewCellConfigure];
    if (self) {
        _text = text;
    }

    return self;
}

@end

示例

在 Xcode 中打开和运行 DFITableViewManagerDemo.xcworkspace,以查看 DFITableViewManager 的实际使用情况。

安装