Latest 0.6.2
Homepage https://github.com/bcylin/QuickTableViewController
License MIT
Platforms ios 8.0, requires ARC

Build Status
Carthage compatible
CocoaPods Compatible
Platform
codecov.io
Swift 3.1

A simple way to create a table view for settings, providing table view cells with:

  • UISwitch
  • Center aligned text
  • Table view cell image
  • Customizable UITableViewCellStyle and UITableViewCellAccessoryType

Usage

Set up tableContents in viewDidLoad:

import QuickTableViewController

class ViewController: QuickTableViewController {

  override func viewDidLoad() {
    super.viewDidLoad()

    tableContents = [
      Section(title: "Switch", rows: [
        SwitchRow<SwitchCell>(title: "Setting 1", switchValue: true, action: { _ in }),
        SwitchRow<SwitchCell>(title: "Setting 2", switchValue: false, action: { _ in }),
      ]),

      Section(title: "Tap Action", rows: [
        TapActionRow<TapActionCell>(title: "Tap action", action: { [weak self] in self?.showAlert($0) })
      ]),

      Section(title: "Navigation", rows: [
        NavigationRow(title: "CellStyle.default", subtitle: .none, icon: Icon(image: UIImage(named: "globe"), highlightedImage: UIImage(named: "globe-highlighted"))),
        NavigationRow(title: "CellStyle", subtitle: .belowTitle(".subtitle"), icon: Icon(image: UIImage(named: "gear"))),
        NavigationRow(title: "CellStyle", subtitle: .rightAligned(".value1"), icon: Icon(imageName: "time"), action: { [weak self] in self?.showDetail($0) }),
        NavigationRow(title: "CellStyle", subtitle: .leftAligned(".value2"))
      ])
    ]
  }

  // MARK: - Actions

  private func showAlert(_ sender: Row) {
    // ...
  }

  private func showDetail(_ sender: Row) {
    // ...
  }

}

NavigationRow

Subtitle Styles

NavigationRow(title: "UITableViewCellStyle.Default", subtitle: .none)
NavigationRow(title: "UITableViewCellStyle", subtitle: .belowTitle(".subtitle")
NavigationRow(title: "UITableViewCellStyle", subtitle: .rightAligned(".value1")
NavigationRow(title: "UITableViewCellStyle", subtitle: .leftAligned(".value2"))

Images

  • Images in table view cells can be set by specifying the icon of each IconEnabled row.
  • The Icon struct carries info about images for both normal and highlighted states.
  • Table view cells in UITableViewCellStyle.value2 will hide images.
NavigationRow(title: "Cell with image", subtitle: .none, icon: Icon(imageName: "icon"))

Disclosure Indicator

  • A NavigationRow with an action will be displayed in a table view cell whose accessoryType is .disclosureIndicator.
  • The action will be invoked when the related table view cell is selected.
NavigationRow(title: "Navigation cell", subtitle: .None, action: { (sender: Row) in })

SwitchRow

  • A SwitchRow is representing a table view cell with a UISwitch as its accessoryView.
  • The action will be invoked when the switch value changes.
  • It also conforms to IconEnabled.
SwitchRow(title: "Switch", switchValue: true, action: { (sender: Row) in }),

TapActionRow

  • A TapActionRow is representing a button-like table view cell.
  • The action will be invoked when the related table view cell is selected.
TapActionRow(title: "Tap action", action: { (sender: Row) in })

Customization

Cell Classes

A customized table view cell type can be specified to rows during initialization.

// NavigationRow, using UITableViewCell if not specified.
NavigationRow<CustomCell>(title: "Navigation", subtitle: .none)

// SwitchRow, using SwitchCell if not specified.
SwitchRow<CustomSwitchCell>(title: "Switch", switchValue: true, action: { _ in })

// TapActionRow, using TapActionCell if not specified.
TapActionRow<CustomTapActionCell>(title: "Tap", action: { _ in })

Table view cell classes that conform to Configurable can implement the additional configuration to set up the cell during tableView(_:cellForRowAt:):

public protocol Configurable {
  func configure(with row: Row & RowStyle)
}

The customization using register(_:forCellReuseIdentifier:) is deprecated.

Note: in 0.5.1 & 0.5.2, SwitchRow and TapActionRow were using String(describing: SwitchCell.self) and String(describing: TapActionCell.self) as reuse identifiers. Fixed in 0.5.3 for backward compatibility.

Rows

All rows must conform to Row and RowStyle. Optional conformation to IconEnabled and AccessoryEnabled are available for customizing the cell image and accessory view.

Documentation

Requirements

QuickTableViewController iOS Xcode Swift
~> 0.1.0 8.0+ 6.4 Swift 1.2
~> 0.2.0 8.0+ 7.0 Swift 2.0
~> 0.3.0 8.0+ 7.3 Swift 2.2
~> 0.4.0 8.0+ 8.0 Swift 2.3
~> 0.5.0 8.0+ 8.0 Swift 3.0
~> 0.6.0 8.0+ 8.3 Swift 3.1

Installation

Use CocoaPods

Create a Podfile with the following specification and run pod install.

platform :ios, '8.0'
use_frameworks!

pod 'QuickTableViewController', '~> 0.6.0'

Use Carthage

Create a Cartfile with the following specification and run carthage update QuickTableViewController.
Follow the instructions to add the framework to your project.

github "bcylin/QuickTableViewController" ~> 0.6.0

Use Git Submodule

git submodule add -b master [email protected]:bcylin/QuickTableViewController.git Dependencies/QuickTableViewController
  • Drag QuickTableViewController.xcodeproj to your app project as a subproject.
  • On your application target’s Build Phases settings tab, add QuickTableViewController-iOS to Target Dependencies.

Contact

Twitter

License

QuickTableViewController is released under the MIT license.
See LICENSE for more details.
Image source: iconmonstr.

Latest podspec

{
    "name": "QuickTableViewController",
    "version": "0.6.2",
    "summary": "A simple way to create a UITableView for settings.",
    "screenshots": "https://bcylin.github.io/QuickTableViewController/img/screenshot.png",
    "homepage": "https://github.com/bcylin/QuickTableViewController",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": "bcylin",
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/bcylin/QuickTableViewController.git",
        "tag": "v0.6.2"
    },
    "source_files": "Source/**/*.swift",
    "requires_arc": true,
    "pushed_with_swift_version": "3.1"
}

Pin It on Pinterest

Share This