TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Oct 2016 |
SPMSupports SPM | ✗ |
Maintained by Nguyen Phu Nghia.
A lazy way for smart developers to deal with UITableView.
How many times do you have to implement UITableViewDatasource and UITableViewDelegate?
Is it boring? And how to deal with different UITableViewCells in one TableView?
You’re smart, so you need a smart way to do it.
ATTableView is for you, it’s easy to display model in UITableView. Also support different UITableViewCells.
Your ViewController has to:
if else
condition if you need to display different UITableViewCells in one TableView.So now:
public protocol ATTableViewCellProtocol: NSObjectProtocol {
typealias ModelType
// Optional, default is ClassName
static func reuseIdentifier() -> String
// Optional, default is ClassName
static func nibName() -> String?
// Optional, default is `UITableViewAutomaticDimension`
static func height(model: ModelType) -> CGFloat
// Define how to map properties of model to UI.
// This method must be implemented.
func configureCell(model: ModelType)
}
ATTableView requires some implementations in your cell, so your cell must implement this protocol.
There’s a sample project in the Demo directory. Or follow the instructions here.
Have fun!
After some setup, using ATTableView is really simple. In your ViewController, just follow these steps below:
1.Register your cells:
self.tableView.register(RestaurantTableViewCell.self)
self.tableView.register(HotelTableViewCell.self)
2.Push your models:
let restaurant = Restaurant()
... // Some extra initializions
let hotel = Hotel()
... // Some extra initializions
self.tableView.addObjects([restaurant, hotel])
3.Enjoy it!
Just easy like this:
self.tableView.onDidSelectItem = { [weak self] item in
// Handle selected item here
...
}
Coming soon…
CocoaPods is a dependency manager for Cocoa projects.
CocoaPods 0.36 adds supports for Swift and embedded frameworks. You can install it with the following command:
$ gem install cocoapods
To integrate ATTableView into your Xcode project using CocoaPods, specify it in your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'ATTableView', '1.2'
Then, run the following command:
$ pod install
ATTableView is released under the MIT license. See LICENSE for details.