Typed, yet Flexible Table View Controller

Overview

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.

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:

struct TextCellViewData {
    let title: String
}

struct ImageCellViewData {
    let image: UIImage
}

and the cells themselves:

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:

import ConfigurableTableViewController

...

let viewController = ConfigurableTableViewController(items: [
    CellConfigurator<TextTableViewCell>(viewData: TextCellViewData(title: "Foo")),
    CellConfigurator<ImageTableViewCell>(viewData: ImageCellViewData(image: apple)),
    CellConfigurator<ImageTableViewCell>(viewData: ImageCellViewData(image: google)),
    CellConfigurator<TextTableViewCell>(viewData: TextCellViewData(title: "Bar")),
    ])

presentViewController(viewController, animated: true, completion: nil)

And ta-da ๐ŸŽˆ :

I encourage you to check both the implementation and an example app.

Demo

To run the example project; clone the repo, open the project and run ExampleApp target.

Requirements

iOS 8 and above.

Author

Arkadiusz Holko:

You might also like...
PreviewTransition is a simple preview gallery UI controller with animated tranisitions.
PreviewTransition is a simple preview gallery UI controller with animated tranisitions.

PreviewTransition is a simple preview gallery UI controller with animated tranisitions. Swift UI library made by @Ramotion

A waterfall grid layout view for SwiftUI.
A waterfall grid layout view for SwiftUI.

WaterfallGrid A waterfall grid layout view for SwiftUI. Features Irregular grid of content. Columns number different per device orientation. Spacing a

๐ŸŽ› QGrid: The missing SwiftUI collection view.
๐ŸŽ› QGrid: The missing SwiftUI collection view.

[NOTE] If you'd like to see QGrid in action, check out this demo of QDesigner (see video below). Install QDesigner: https://apps.apple.com/us/app/qdes

Display list of Marvel comic Characters and its detail view
Display list of Marvel comic Characters and its detail view

Marvel Universe Display list of Marvel comic Characters and its detail view Installation Dependencies in this project are provided via Xcodegen (proje

 Building An Interactive Grid View
Building An Interactive Grid View

Building An Interactive Grid View This demo shows a few techniques on how to build a re-ordable grid view based on stock UICollectionView API. Here ar

An easy-to-use UITableViewCell subclass that implements a swippable content view which exposes utility buttons (similar to iOS 7 Mail Application)
An easy-to-use UITableViewCell subclass that implements a swippable content view which exposes utility buttons (similar to iOS 7 Mail Application)

SWTableViewCell An easy-to-use UITableViewCell subclass that implements a swipeable content view which exposes utility buttons (similar to iOS 7 Mail

Objective-C library for drag-n-drop of UITableViewCells in a navigation hierarchy of view controllers.
Objective-C library for drag-n-drop of UITableViewCells in a navigation hierarchy of view controllers.

ios-dragable-table-cells Support for drag-n-drop of UITableViewCells in a navigation hierarchy of view controllers. You drag cells by tapping and hold

Simple timeline view implemented by UITableViewCell
Simple timeline view implemented by UITableViewCell

TimelineTableViewCell TimelineTableViewCell is a simple timeline view implemented by UITableViewCell. The UI design of TimelineTableViewCell is inspir

XLForm is the most flexible and powerful iOS library to create dynamic table-view forms. Fully compatible with Swift & Obj-C.
XLForm is the most flexible and powerful iOS library to create dynamic table-view forms. Fully compatible with Swift & Obj-C.

XLForm By XMARTLABS. If you are working in Swift then you should have a look at Eureka, a complete re-design of XLForm in Swift and with more features

SwiftMessages is a very flexible view and view controller presentation library for iOS.
SwiftMessages is a very flexible view and view controller presentation library for iOS.

SwiftMessages Overview SwiftMessages is a very flexible view and view controller presentation library for iOS. Message views and view controllers can

Generic table view controller with external data processing
Generic table view controller with external data processing

FlexibleTableViewController Swift library of generic table view controller with external data processing of functionality, like determine cell's reuse

๐ŸŒŠ - Jelly is a library for animated, non-interactive & interactive viewcontroller  transitions and presentations with the focus on a simple and yet flexible API.
๐ŸŒŠ - Jelly is a library for animated, non-interactive & interactive viewcontroller transitions and presentations with the focus on a simple and yet flexible API.

Jelly is a library for animated, non-interactive & interactive viewcontroller transitions and presentations with the focus on a simple and yet flexibl

A fast & simple, yet powerful & flexible logging framework for Mac and iOS
A fast & simple, yet powerful & flexible logging framework for Mac and iOS

CocoaLumberjack CocoaLumberjack is a fast & simple, yet powerful & flexible logging framework for macOS, iOS, tvOS and watchOS. How to get started Fir

UIKit drop down menu, simple yet flexible and written in Swift
UIKit drop down menu, simple yet flexible and written in Swift

DropDownMenuKit DropDownMenuKit is a custom UIKit control to show a menu attached to the navigation bar or toolbar. The menu appears with a sliding an

๐ŸŒŠ - Jelly is a library for animated, non-interactive & interactive viewcontroller  transitions and presentations with the focus on a simple and yet flexible API.
๐ŸŒŠ - Jelly is a library for animated, non-interactive & interactive viewcontroller transitions and presentations with the focus on a simple and yet flexible API.

Jelly is a library for animated, non-interactive & interactive viewcontroller transitions and presentations with the focus on a simple and yet flexibl

A controller that uses a UIStackView and view controller composition to display content in a list
A controller that uses a UIStackView and view controller composition to display content in a list

StackViewController Overview StackViewController is a Swift framework that simplifies the process of building forms and other static content using UIS

A simple yet customizable horizontal and vertical picker view
A simple yet customizable horizontal and vertical picker view

WheelPicker A simple yet customizable horizontal and vertical picker view Features Vertical or Horizontal picker Image or Text data Configure UILabel

Use Yelp API to fetch restuarants around a location and show them in a table view
Use Yelp API to fetch restuarants around a location and show them in a table view

Yelp Use Yelp API to fetch restuarants around a location and show them in a table view - Infinite scrolling, Prefetching, Image Caching. Design Patter

Using UI Table View
Using UI Table View

News-App Table View์™€ Table view controller Table View : Table์˜ ํฌ๊ธฐ๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. Table View Controller: ์ „์ฒด์˜ ๋ทฐ๊ฐ€ ํ•˜๋‚˜์˜ ํ…Œ์ด๋ธ” Table View Table view ๊ตฌ์„ฑ์š”์†Œ ๊ฒฐ์ •ํ•˜๊ธฐ ์–ด๋–ค

Comments
  • didSelectRowAtIndexPath method

    didSelectRowAtIndexPath method

    I really like this example and I start using it. I have just one question. How would method didSelectRowAtIndexPath look like? What's best solution for this? Thanks

    opened by LiborZ 2
  • Add sections support

    Add sections support

    Adds support for sections.

    Next would be to:

    1. Improve SectionConfigurator with section header info.
    2. Extend functionality to support collection views.
    3. Support registering nibs
    opened by sharoni 0
Use Yelp API to fetch restuarants around a location and show them in a table view

Yelp Use Yelp API to fetch restuarants around a location and show them in a table view - Infinite scrolling, Prefetching, Image Caching. Design Patter

null 0 Nov 1, 2021
Using UI Table View

News-App Table View์™€ Table view controller Table View : Table์˜ ํฌ๊ธฐ๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. Table View Controller: ์ „์ฒด์˜ ๋ทฐ๊ฐ€ ํ•˜๋‚˜์˜ ํ…Œ์ด๋ธ” Table View Table view ๊ตฌ์„ฑ์š”์†Œ ๊ฒฐ์ •ํ•˜๊ธฐ ์–ด๋–ค

Jiwon 0 Dec 9, 2021
A UITableView extension that enables cell insertion from the bottom of a table view.

ReverseExtension UITableView extension that enabled to insert cell from bottom of tableView. Concept It is difficult to fill a tableview content from

Taiki Suzuki 1.7k Dec 15, 2022
TableViews - Emoji Table View For iOS With Swift

TableViews Hello! This is EmojiTableView. Let me introduce you my first app when

null 0 Jan 2, 2022
A flexible grid layout view for SwiftUI

?? GridStack A flexible grid layout view for SwiftUI. WWDC20 Update Apple ๏ฃฟ released LazyVGrid and LazyHGrid at WWDC20. If you are fine to only suppor

Peter Minarik 620 Nov 11, 2022
Simple static table views for iOS in Swift.

Simple static table views for iOS in Swift. Static's goal is to separate model data from presentation. Rows and Sections are your โ€œview modelsโ€ for yo

Venmo 1.3k Nov 19, 2022
A Swift library for swipeable table cells

BWSwipeRevealCell Using the library **Note: Use version 1.0.1 for Swift 2.3 support and version 2.0.0 or higher for Swift 3 support ** There are two m

Kyle Newsome 67 May 11, 2022
Type-safe declarative table views.

TableKit TableKit is a super lightweight yet powerful generic library that allows you to build complex table views in a declarative type-safe manner.

Max Sokolov 694 Dec 13, 2022
This framework allows you to build Table views using UIKit with syntax similar to SwiftUI

This framework allows you to build Table views using UIKit with syntax similar to SwiftUI

Fun 60 Dec 17, 2022