Skip to content

Commit e23d9a4

Browse files
committed
Merge branch 'feature/accessory-type' into develop
2 parents 5e2eaad + f3e351b commit e23d9a4

12 files changed

Lines changed: 174 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Rename `Row`'s title and subtitle to text and detail text to align with `UITableViewCell`'s naming
88
* `Subtitle` is deprecated and will be removed in **v2.0.0**
99
* Enable **detailText** in `OptionRow` and `SwitchRow`
10+
* Add **accessoryButtonAction** to `NavigationRow`
1011

1112
## v1.0.0
1213

Example-iOS/ViewControllers/DefaultViewController.swift renamed to Example-iOS/ViewControllers/ExampleViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// DefaultViewController.swift
2+
// ExampleViewController.swift
33
// Example-iOS
44
//
55
// Created by Ben on 01/09/2015.
@@ -27,7 +27,7 @@
2727
import UIKit
2828
import QuickTableViewController
2929

30-
internal final class DefaultViewController: QuickTableViewController {
30+
internal final class ExampleViewController: QuickTableViewController {
3131

3232
// MARK: - Properties
3333

@@ -55,7 +55,7 @@ internal final class DefaultViewController: QuickTableViewController {
5555

5656
Section(title: "Navigation", rows: [
5757
NavigationRow(text: "CellStyle.default", detailText: .none, icon: .image(gear)),
58-
NavigationRow(text: "CellStyle", detailText: .subtitle(".subtitle"), icon: .image(globe)),
58+
NavigationRow(text: "CellStyle", detailText: .subtitle(".subtitle"), icon: .image(globe), accessoryButtonAction: showDetail()),
5959
NavigationRow(text: "CellStyle", detailText: .value1(".value1"), icon: .image(time), action: showDetail()),
6060
NavigationRow(text: "CellStyle", detailText: .value2(".value2"))
6161
], footer: "UITableViewCellStyle.Value2 hides the image view."),

Example-iOS/ViewControllers/RootViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ internal final class RootViewController: QuickTableViewController {
4141
tableContents = [
4242
Section(title: "Default", rows: [
4343
NavigationRow(text: "Use default cell types", detailText: .none, action: { [weak self] _ in
44-
self?.navigationController?.pushViewController(DefaultViewController(), animated: true)
44+
self?.navigationController?.pushViewController(ExampleViewController(), animated: true)
4545
})
4646
]),
4747

Example-iOSUITests/ExampleUITests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ internal final class ExampleUITests: XCTestCase {
6868
return false
6969
}
7070

71+
tables.cells.containing(.staticText, identifier: ".subtitle").buttons["More Info"].tap()
72+
app.navigationBars.buttons.element(boundBy: 0).tap()
73+
expectation(for: existance, evaluatedWith: tables.staticTexts["CellStyle.subtitle is selected"], handler: nil)
74+
waitForExpectations(timeout: 5, handler: nil)
75+
7176
tables.staticTexts[".value1"].tap()
7277
app.navigationBars.buttons.element(boundBy: 0).tap()
7378
expectation(for: existance, evaluatedWith: tables.staticTexts["CellStyle.value1 is selected"], handler: nil)

Example-tvOS/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ internal final class AppDelegate: UIResponder, UIApplicationDelegate {
3333

3434
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
3535
window = UIWindow(frame: UIScreen.main.bounds)
36-
window?.rootViewController = UINavigationController(rootViewController: TableViewController())
36+
window?.rootViewController = UINavigationController(rootViewController: ExampleViewController())
3737
window?.makeKeyAndVisible()
3838
return true
3939
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// TableViewController.swift
2+
// ExampleViewController.swift
33
// Example-tvOS
44
//
55
// Created by Ben on 19/04/2018.
@@ -27,7 +27,7 @@
2727
import UIKit
2828
import QuickTableViewController
2929

30-
internal final class TableViewController: QuickTableViewController {
30+
internal final class ExampleViewController: QuickTableViewController {
3131

3232
override func viewDidLoad() {
3333
super.viewDidLoad()

QuickTableViewController.xcodeproj/project.pbxproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
A7A26A71AB271F9D402D1A12 /* Pods_Example_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BF3454E57819285B32968564 /* Pods_Example_iOS.framework */; };
2323
B50E73851F2E1BC900481910 /* RowStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = B50E73841F2E1BC900481910 /* RowStyle.swift */; };
2424
B51F21A51F417037009BC2C9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51F21A41F417037009BC2C9 /* AppDelegate.swift */; };
25-
B51F21A71F417037009BC2C9 /* DefaultViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51F21A61F417037009BC2C9 /* DefaultViewController.swift */; };
25+
B51F21A71F417037009BC2C9 /* ExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51F21A61F417037009BC2C9 /* ExampleViewController.swift */; };
2626
B51F21AC1F417037009BC2C9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B51F21AB1F417037009BC2C9 /* Assets.xcassets */; };
2727
B51F21B61F41709B009BC2C9 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = B51F21B41F41709B009BC2C9 /* LaunchScreen.xib */; };
2828
B51F21C31F41E600009BC2C9 /* ExampleUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51F21C21F41E600009BC2C9 /* ExampleUITests.swift */; };
@@ -54,7 +54,7 @@
5454
B54A244D208883A300EEBA26 /* TapActionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B595627A1B9758BC00D6DAB1 /* TapActionCell.swift */; };
5555
B54A244E208883A300EEBA26 /* QuickTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5334F2F1B8CC6AA00C64A6D /* QuickTableViewController.swift */; };
5656
B54A24562088D44A00EEBA26 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B54A24552088D44A00EEBA26 /* AppDelegate.swift */; };
57-
B54A24582088D44A00EEBA26 /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B54A24572088D44A00EEBA26 /* TableViewController.swift */; };
57+
B54A24582088D44A00EEBA26 /* ExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B54A24572088D44A00EEBA26 /* ExampleViewController.swift */; };
5858
B54A245D2088D44D00EEBA26 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B54A245C2088D44D00EEBA26 /* Assets.xcassets */; };
5959
B55475751F2DC3C00027F7C1 /* Configurable.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55475741F2DC3C00027F7C1 /* Configurable.swift */; };
6060
B578B5091C5673240021F7C3 /* icon.png in Resources */ = {isa = PBXBuildFile; fileRef = B578B5071C5673240021F7C3 /* icon.png */; };
@@ -193,7 +193,7 @@
193193
B50E73841F2E1BC900481910 /* RowStyle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowStyle.swift; sourceTree = "<group>"; };
194194
B51F21A21F417037009BC2C9 /* Example-iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Example-iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
195195
B51F21A41F417037009BC2C9 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
196-
B51F21A61F417037009BC2C9 /* DefaultViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultViewController.swift; sourceTree = "<group>"; };
196+
B51F21A61F417037009BC2C9 /* ExampleViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExampleViewController.swift; sourceTree = "<group>"; };
197197
B51F21AB1F417037009BC2C9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
198198
B51F21B01F417037009BC2C9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
199199
B51F21B51F41709B009BC2C9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
@@ -218,7 +218,7 @@
218218
B54A24352088816E00EEBA26 /* Info-tvOSTests.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-tvOSTests.plist"; sourceTree = "<group>"; };
219219
B54A24532088D44A00EEBA26 /* Example-tvOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Example-tvOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
220220
B54A24552088D44A00EEBA26 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
221-
B54A24572088D44A00EEBA26 /* TableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = "<group>"; };
221+
B54A24572088D44A00EEBA26 /* ExampleViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExampleViewController.swift; sourceTree = "<group>"; };
222222
B54A245C2088D44D00EEBA26 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
223223
B54A245E2088D44D00EEBA26 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
224224
B55475741F2DC3C00027F7C1 /* Configurable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Configurable.swift; sourceTree = "<group>"; };
@@ -527,8 +527,8 @@
527527
children = (
528528
B54A24552088D44A00EEBA26 /* AppDelegate.swift */,
529529
B54A245C2088D44D00EEBA26 /* Assets.xcassets */,
530+
B54A24572088D44A00EEBA26 /* ExampleViewController.swift */,
530531
B54A245E2088D44D00EEBA26 /* Info.plist */,
531-
B54A24572088D44A00EEBA26 /* TableViewController.swift */,
532532
);
533533
path = "Example-tvOS";
534534
sourceTree = "<group>";
@@ -571,7 +571,7 @@
571571
children = (
572572
B5A37EAD20208EF7009C075F /* AppearanceViewController.swift */,
573573
B5A67A1120205F5C0075E0C8 /* CustomizationViewController.swift */,
574-
B51F21A61F417037009BC2C9 /* DefaultViewController.swift */,
574+
B51F21A61F417037009BC2C9 /* ExampleViewController.swift */,
575575
B5A67A13202069440075E0C8 /* RootViewController.swift */,
576576
);
577577
path = ViewControllers;
@@ -1106,7 +1106,7 @@
11061106
B51F21A51F417037009BC2C9 /* AppDelegate.swift in Sources */,
11071107
B5A37EAE20208EF7009C075F /* AppearanceViewController.swift in Sources */,
11081108
B5A67A1220205F5C0075E0C8 /* CustomizationViewController.swift in Sources */,
1109-
B51F21A71F417037009BC2C9 /* DefaultViewController.swift in Sources */,
1109+
B51F21A71F417037009BC2C9 /* ExampleViewController.swift in Sources */,
11101110
B5A67A14202069440075E0C8 /* RootViewController.swift in Sources */,
11111111
);
11121112
runOnlyForDeploymentPostprocessing = 0;
@@ -1218,7 +1218,7 @@
12181218
buildActionMask = 2147483647;
12191219
files = (
12201220
B54A24562088D44A00EEBA26 /* AppDelegate.swift in Sources */,
1221-
B54A24582088D44A00EEBA26 /* TableViewController.swift in Sources */,
1221+
B54A24582088D44A00EEBA26 /* ExampleViewController.swift in Sources */,
12221222
);
12231223
runOnlyForDeploymentPostprocessing = 0;
12241224
};

Source/Protocol/RowCompatible.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727
import Foundation
2828

2929
/// This protocol defines the compatible interface of a `NavigationRow` regardless of its associated cell type.
30-
public protocol NavigationRowCompatible: Row, RowStyle {}
30+
public protocol NavigationRowCompatible: Row, RowStyle {
31+
#if os(iOS)
32+
/// A closure that will be invoked when the accessory button is selected.
33+
var accessoryButtonAction: ((Row) -> Void)? { get }
34+
#endif
35+
}
3136

3237

3338
/// This protocol defines the compatible interface of a `TapActionRow` regardless of its associated cell type.

Source/QuickTableViewController.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,17 @@ open class QuickTableViewController: UIViewController, UITableViewDataSource, UI
165165
}
166166
}
167167

168+
#if os(iOS)
169+
public func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
170+
switch tableContents[indexPath.section].rows[indexPath.row] {
171+
case let row as NavigationRowCompatible:
172+
row.accessoryButtonAction?(row)
173+
default:
174+
break
175+
}
176+
}
177+
#endif
178+
168179
}
169180

170181

Source/Rows/NavigationRow.swift

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,28 @@ open class NavigationRow<T: UITableViewCell>: NavigationRowCompatible, Equatable
3131

3232
// MARK: - Initializer
3333

34+
#if os(iOS)
35+
36+
/// Initializes a `NavigationRow` with a text and a detail text.
37+
/// The icon, customization, action and accessory button action closures are optional.
38+
public init(
39+
text: String,
40+
detailText: DetailText,
41+
icon: Icon? = nil,
42+
customization: ((UITableViewCell, Row & RowStyle) -> Void)? = nil,
43+
action: ((Row) -> Void)? = nil,
44+
accessoryButtonAction: ((Row) -> Void)? = nil
45+
) {
46+
self.text = text
47+
self.detailText = detailText
48+
self.icon = icon
49+
self.customize = customization
50+
self.action = action
51+
self.accessoryButtonAction = accessoryButtonAction
52+
}
53+
54+
#elseif os(tvOS)
55+
3456
/// Initializes a `NavigationRow` with a text and a detail text.
3557
/// The icon, customization and action closures are optional.
3658
public init(
@@ -47,6 +69,8 @@ open class NavigationRow<T: UITableViewCell>: NavigationRowCompatible, Equatable
4769
self.action = action
4870
}
4971

72+
#endif
73+
5074
// MARK: - Row
5175

5276
/// The text of the row.
@@ -58,6 +82,13 @@ open class NavigationRow<T: UITableViewCell>: NavigationRowCompatible, Equatable
5882
/// A closure that will be invoked when the row is selected.
5983
public let action: ((Row) -> Void)?
6084

85+
#if os(iOS)
86+
87+
/// A closure that will be invoked when the accessory button is selected.
88+
public let accessoryButtonAction: ((Row) -> Void)?
89+
90+
#endif
91+
6192
// MARK: - RowStyle
6293

6394
/// The type of the table view cell to display the row.
@@ -76,9 +107,19 @@ open class NavigationRow<T: UITableViewCell>: NavigationRowCompatible, Equatable
76107
/// The icon of the row.
77108
public let icon: Icon?
78109

79-
/// Returns `.disclosureIndicator` when action is not nil, otherwise returns `.none`.
110+
/// Returns the accessory type with the disclosure indicator when `action` is not nil,
111+
/// and with the detail button when `accessoryButtonAction` is not nil.
80112
public var accessoryType: UITableViewCell.AccessoryType {
81-
return (action == nil) ? .none : .disclosureIndicator
113+
#if os(iOS)
114+
switch (action, accessoryButtonAction) {
115+
case (nil, nil): return .none
116+
case (.some, nil): return .disclosureIndicator
117+
case (nil, .some): return .detailButton
118+
case (.some, .some): return .detailDisclosureButton
119+
}
120+
#elseif os(tvOS)
121+
return (action == nil) ? .none : .disclosureIndicator
122+
#endif
82123
}
83124

84125
/// The `NavigationRow` is selectable when action is not nil.

0 commit comments

Comments
 (0)