A simple way to create a table view for settings, providing table view cells with:
- UISwitch
- Center aligned text
- Table view cell image
- Disclosure indicator
- Specified UITableViewCellStyle
Set up tableContents in viewDidLoad:
import QuickTableViewController
class ViewController: QuickTableViewController {
override func viewDidLoad() {
super.viewDidLoad()
tableContents = [
Section(title: "Switch", rows: [
SwitchRow(title: "Setting 1", switchValue: true, action: { _ in }),
SwitchRow(title: "Setting 2", switchValue: false, action: { _ in }),
]),
Section(title: "Tap Action", rows: [
TapActionRow(title: "Tap action", action: { [weak self] in self?.showAlert($0) })
]),
Section(title: "Cell Styles", rows: [
NavigationRow(title: "CellStyle.Default", subtitle: .None, icon: Icon(image: UIImage(named: "exit"), highlightedImage: UIImage(named: "exit-highlighted"))),
NavigationRow(title: "CellStyle", subtitle: .BelowTitle(".Subtitle"), icon: Icon(image: UIImage(named: "language"))),
NavigationRow(title: "CellStyle", subtitle: .RightAligned(".Value1"), icon: Icon(imageName: "timeMachine"), 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(title: "UITableViewCellStyle.Default", subtitle: .None)
NavigationRow(title: "UITableViewCellStyle", subtitle: .BelowTitle(".Subtitle")
NavigationRow(title: "UITableViewCellStyle", subtitle: .RightAligned(".Value1")
NavigationRow(title: "UITableViewCellStyle", subtitle: .LeftAligned(".Value2"))- Images in table view cells can be set by specifying the
iconof eachIconEnabledrow. - The
Iconstruct carries info about images for both normal and highlighted states. - Table view cells in
UITableViewCellStyle.Value2will hide images.
NavigationRow(title: "Cell with image", subtitle: .None, icon: Icon(imageName: "icon"))- A
NavigationRowwith anactionwill be displayed in a table view cell whoseaccessoryTypeis.DisclosureIndicator. - The
actionwill be invoked when the related table view cell is selected.
NavigationRow(title: "Navigation cell", subtitle: .None, action: { (sender: Row) in })- A
SwitchRowis associated to a table view cell with aUISwitchas itsaccessoryView. - The optional
actionwill be invoked when theswitchValuechanges. - It also conforms to
IconEnabled.
SwitchRow(title: "Switch", switchValue: true, action: { (sender: Row) in }),The original
SwitchRowin thetableContentswill be replaced by an updated one after theswitchValuechanged.
- A
TapActionRowis associated to a button-like table view cell. - The
actionwill be invoked when the related table view cell is selected.
TapActionRow(title: "Tap action", action: { (sender: Row) in })// NavigationRow
tableView.register(CustomCell.self, forCellReuseIdentifier: "Subtitle.None")
tableView.register(CustomSubtitleCell.self, forCellReuseIdentifier: "Subtitle.BelowTitle")
tableView.register(CustomValue1StyleCell.self, forCellReuseIdentifier: "Subtitle.RightAligned")
tableView.register(CustomValue2StyleCell.self, forCellReuseIdentifier: "Subtitle.LeftAligned")// SwitchRow
tableView.register(CustomSwitchCell.self, forCellReuseIdentifier: NSStringFromClass(SwitchCell.self))
// TapActionRow
tableView.register(CustomTapActionCell.self, forCellReuseIdentifier: NSStringFromClass(TapActionCell.self))Note: in
0.5.1&0.5.2, SwitchRow and TapActionRow were usingString(describing: SwitchCell.self)andString(describing: TapActionCell.self)as reuse identifiers. Fixed in0.5.3for backward compatibility.
https://bcylin.github.io/QuickTableViewController
| QuickTableViewController | iOS | Xcode | Swift |
|---|---|---|---|
~> 0.1.0 |
8.0+ | 6.4 | |
~> 0.2.0 |
8.0+ | 7.0 | |
~> 0.3.0 |
8.0+ | 7.3 | |
~> 0.4.0 |
8.0+ | 8.0 | |
~> 0.5.0 |
8.0+ | 8.0 |
Use CocoaPods
Create a Podfile with the following specification and run pod install.
platform :ios, '8.0'
use_frameworks!
pod 'QuickTableViewController', '~> 0.5.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.5.0
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.
QuickTableViewController is released under the MIT license. See LICENSE for more details. Image source: iconmonstr.
