• This repository has been archived on 02/Mar/2019
  • Stars
    star
    162
  • Rank 232,284 (Top 5 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A data-driven UITableView framework

Version Platform Language License

MDTables

An elegant way to create tableView

let row0 = Row(title: "System Cell", accessoryType: .disclosureIndicator)
row0.onDidSelected { (tableView, indexPath) in
    tableView.deselectRow(at: indexPath, animated: true)
}
let row1 = Row(title: "Custom Cell", accessoryType: .disclosureIndicator)
    
let section0 = Section(rows: [row0,row1])
section0.titleForHeader = "Basic"
section0.heightForHeader = 30.0
    
tableView.manager = TableManager(sections: [section0])

And your tableView is ready.

Demo

The example project contains a demo of NeteaseCloudMusic。(以网易云音乐首页作为Demo)

Require

  • Xcode 8.1+
  • iOS 8.0+
  • Swift 3.0+

Install

CocoaPod

pod "MDTable"

Carthage

github "LeoMobileDeveloper/MDTable"

Useage

Basic concept

MDTable offers tow basic types:

  • Row - model of Cell.
  • Section- model of Section

You create rows and sections.

let row = Row(title: "System Cell", accessoryType: .disclosureIndicator)
let section0 = Section(rows: row)

Then use declarative API to handle event

row.onWillDisplay { (tableView, cell, indexPath) in
    //Access manager with tableView.manager
}
row.onDidSelected { (tableView, indexPath) in }

Then,create a manager and bind it to tableView

tableView.manager = TableManager(sections: [section0])

Custom Cell

Model

Create a subClass of ReactiveRow,

class XibRow:ReactiveRow{
    //Data
    var title:String
    var subTitle:String
    var image:UIImage
    init(title:String, subTitle:String, image:UIImage) {
        self.title = title
        self.subTitle = subTitle
        self.image = image
        super.init()
        self.rowHeight = 80.0
        self.reuseIdentifier = "XibRow" //Default reuseIdentifier is class Name
        self.initalType = RowConvertableInitalType.xib(xibName: "CusomCellWithXib") // How row is created
    }

}

Cell

Create a subclass of MDTableViewCell,and override render

class CusomCellWithXib: MDTableViewCell{    
    override func render(with row: TableRow) {
        guard let row = row as? XibRow else{
            return;
        }
        //Render the cell 
    }
}

Magic happens

let row = XibRow(title: "Title", subTitle: "Subtitle", image: UIImage(named: "avatar")!)
row.onDidSelected({ (tableView, indexPath) in
    tableView.manager?.delete(row: indexPath)
    tableView.deleteRows(at: [indexPath], with: .automatic)
})
let section = Section(rows: rows)
section.heightForHeader = 30.0
section.titleForHeader = "Tap Row to Delete"
tableView.manager = TableManager(sections: [section])

Note

You need to use [unowned self] to avoid retain circle

row.onDidSelected = { [unowned self] (tableView, indexPath) in
}

Author

Leo, [email protected]

License

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

More Repositories

1

ios-developer-tools

Tools that every iOS developer should know.
Swift
1,667
star
2

Blogs

一点心得 - iOS,Swift,React Native,Python...
Objective-C
1,593
star
3

ReactNativeMaterials

React Native的中文参考资料,包括开源库,文字/视频资料,相关工具等
704
star
4

PullToRefreshKit

【Deprecated】Pull to refresh in Swift, easy to use, easy to customize(下拉刷新/QQ/淘宝/优酷/雅虎天气/大众点评)
Swift
554
star
5

awesome-rxswift

An "awesome" type curated list of RxSwift library and learning material
Swift
500
star
6

QTEventBus

iOS事件总线,支持AppDelegate解耦,支持基于响应链的局部总线
Objective-C
428
star
7

ImageMaskTransition

Elegant image transition between view controllers,support both Modal and Push
Swift
121
star
8

LeoDanmakuKit

An iOS Danmaku Kit (添加纯文字弹幕)
Objective-C
52
star
9

LHPerformanceStatusBar

A status bar to show FPS, CPU and memory usage
Objective-C
51
star
10

WCGradientCircleLayer

Draw Gradient Layer from one color to another
Objective-C
36
star
11

ParallexBanner

【Deprecated】A banner scrollview to show images with parallex effect
Swift
30
star
12

LHNavigationController

像网易新闻那样,支持全屏push/pop的导航控制器(A NavigationController that allow you to push/pop with full screen gesture)
Objective-C
26
star
13

DraggableTableView

【Deprecated】Extension for the UITableView that allows a user to move cells with long press and drop.
Swift
26
star
14

LHProgressHUD

A modern ProgressHUD with wonderful animation
Objective-C
23
star
15

LHCityPickerController

包含所有地级市的城市选择控制器,和大众点评类似
Objective-C
13
star
16

React-Native-Files

A project used to store temp files
12
star
17

SwiftDynamicTableviewHeight

A project about how to do dynamic height with system cell
Swift
12
star
18

LeoMobileDeveloper

1
star