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
iconof eachNavigationRow. - 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.
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 })v0.1requires Swift 1.2 and iOS 8.0+ with Xcode 6.4.v0.2is now in Swift 2 with Xcode 7.0 or above.
Install via Carthage
-
Create a
Cartfilewith 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.frameworkfrom 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-frameworksand 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
Podfilewith the following specification and runpod install.platform :ios, '8.0' use_frameworks! pod 'QuickTableViewController', git: 'https://github.com/bcylin/QuickTableViewController.git'
- Copy
*.swiftfiles in theSourcedirectory to an iOS project.
QuickTableViewController is released under the MIT license. See LICENSE for more info.
