Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fastred/ConfigurableTableViewController
Typed, yet Flexible Table View Controller
https://github.com/fastred/ConfigurableTableViewController
Last synced: about 1 month ago
JSON representation
Typed, yet Flexible Table View Controller
- Host: GitHub
- URL: https://github.com/fastred/ConfigurableTableViewController
- Owner: fastred
- Created: 2016-01-03T12:38:30.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-10-23T13:17:04.000Z (about 8 years ago)
- Last Synced: 2024-11-29T00:23:25.100Z (about 2 months ago)
- Language: Swift
- Homepage: http://holko.pl/2016/01/05/typed-table-view-controller/
- Size: 125 KB
- Stars: 269
- Watchers: 10
- Forks: 25
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-ios - ConfigurableTableViewController - Typed, yet Flexible Table View Controller https://holko.pl/2016/01/05/typed-table-view-controller/ (UI / Table View / Collection View)
- awesome-ios-star - ConfigurableTableViewController - Typed, yet Flexible Table View Controller https://holko.pl/2016/01/05/typed-table-view-controller/ (UI / Table View / Collection View)
README
# ConfigurableTableViewController
Simple view controller that provides a way to configure a table view with multiple types of cells while keeping type safety. To learn what and whys I encourage you to read the [associated blog post][blog-post].
## Usage
Let's say we want to present a table view controller with four rows: two with text and two with images. We start by creating view data structures that cells will be configurable with:
```swift
struct TextCellViewData {
let title: String
}struct ImageCellViewData {
let image: UIImage
}
```and the cells themselves:
```swift
class TextTableViewCell: UITableViewCell {
func updateWithViewData(viewData: TextCellViewData) {
textLabel?.text = viewData.title
}
}class ImageTableViewCell: UITableViewCell {
func updateWithViewData(viewData: ImageCellViewData) {
imageView?.image = viewData.image
}
}
```Now to present a table view controller with those cells, we simply configure it in the following way:
```swift
import ConfigurableTableViewController...
let viewController = ConfigurableTableViewController(items: [
CellConfigurator(viewData: TextCellViewData(title: "Foo")),
CellConfigurator(viewData: ImageCellViewData(image: apple)),
CellConfigurator(viewData: ImageCellViewData(image: google)),
CellConfigurator(viewData: TextCellViewData(title: "Bar")),
])presentViewController(viewController, animated: true, completion: nil)
```And ta-da :balloon::
I encourage you to check both the [implementation][Framework] and an [example app][ExampleApp].
## Demo
To run the example project; clone the repo, open the project and run `ExampleApp` target.
## Requirements
iOS 8 and above.
## Author
Arkadiusz Holko:
* [Blog](http://holko.pl/)
* [@arekholko on Twitter](https://twitter.com/arekholko)[Framework]: https://github.com/fastred/ConfigurableTableViewController/tree/master/Framework
[ExampleApp]: https://github.com/fastred/ConfigurableTableViewController/tree/master/ExampleApp
[blog-post]: http://holko.pl/2016/01/05/typed-table-view-controller/