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: showAlert)
]),
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: showDetail),
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
icon
of eachNavigationRow
. - 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"))
- A
NavigationRow
with anaction
will be displayed in a table view cell whoseaccessoryType
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 })
- A
SwitchRow
is associated to a table view cell with aUISwitch
as itsaccessoryView
. - The optional
action
will be invoked when theswitchValue
changes.
SwitchRow(title: "Switch", switchValue: true, action: { (sender: Row) in }),
The original
SwitchRow
in thetableContents
will be replaced by an updated one after theswitchValue
changed.
- A
TapActionRow
is associated to 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 })
v0.1
requires Swift 1.2 and iOS 8.0+ with Xcode 6.4.v0.2
is now in Swift 2 with Xcode 7.0 or above.
Install via Carthage
-
Create a
Cartfile
with the following specification and runcarthage bootstrap
.github "bcylin/QuickTableViewController"
-
On your application targets' General settings tab, in the Linked Frameworks and Libraries section, drag and drop
QuickTableViewController.framework
from the Carthage/Build folder. -
On your application targets’ Build Phases settings tab, click the + icon and choose New Run Script Phase. Create a Run Script with the following contents:
/usr/local/bin/carthage copy-frameworks
and add the following path to Input Files:
$(SRCROOT)/Carthage/Build/iOS/QuickTableViewController.framework
-
For more information, please check out the Carthage Documentation.
Install via CocoaPods
-
Create a
Podfile
with the following specification and runpod install
.platform :ios, '8.0' use_frameworks! pod 'QuickTableViewController', git: 'https://github.com/bcylin/QuickTableViewController.git'
- Copy
*.swift
files in theSource
directory to an iOS project.
QuickTableViewController is released under the MIT license. See LICENSE for more info.