@@ -30,9 +30,17 @@ import Weakify
30
30
31
31
internal final class ViewController : QuickTableViewController {
32
32
33
+ private final class CustomCell : UITableViewCell { }
34
+
33
35
// MARK: - Properties
34
36
35
- let debuggingSection = Section ( title: nil , rows: [ ] )
37
+ private lazy var options : Section = RadioSection ( title: " Radio Buttons " , options: [
38
+ OptionRow ( title: " Option 1 " , isSelected: true , action: weakify ( self , type ( of: self ) . didToggleSelection) ) ,
39
+ OptionRow ( title: " Option 2 " , isSelected: false , action: weakify ( self , type ( of: self ) . didToggleSelection) ) ,
40
+ OptionRow ( title: " Option 3 " , isSelected: false , action: weakify ( self , type ( of: self ) . didToggleSelection) )
41
+ ] , footer: " See RadioSection for more details. " )
42
+
43
+ private let debugging = Section ( title: nil , rows: [ ] )
36
44
37
45
// MARK: - UIViewController
38
46
@@ -62,52 +70,35 @@ internal final class ViewController: QuickTableViewController {
62
70
] , footer: " UITableViewCellStyle.Value2 hides the image view. " ) ,
63
71
64
72
Section ( title: nil , rows: [
65
- NavigationRow ( title: " Empty section title " , subtitle: . none)
73
+ NavigationRow < CustomCell > ( title: " Empty section title " , subtitle: . none, customization: { cell, row in
74
+ cell. accessoryView = UIImageView ( image: #imageLiteral( resourceName: " iconmonstr-x-mark " ) )
75
+ print ( row. cellReuseIdentifier)
76
+ } )
66
77
] ) ,
67
78
68
- Section ( title: " Customized " , rows: [
69
- OptionRow ( title: " Option 1 " , isSelected: true , action: weakify ( self , type ( of: self ) . didToggleSelection) ) ,
70
- OptionRow ( title: " Option 2 " , action: weakify ( self , type ( of: self ) . didToggleSelection) ) ,
71
- OptionRow ( title: " Option 3 " , action: weakify ( self , type ( of: self ) . didToggleSelection) )
72
- ] , footer: " See OptionRow for more details. " ) ,
73
-
74
- debuggingSection
79
+ options,
80
+ debugging
75
81
]
76
82
}
77
83
78
84
// MARK: - UITableViewDataSource
79
85
80
86
override func tableView( _ tableView: UITableView , cellForRowAt indexPath: IndexPath ) -> UITableViewCell {
81
87
let cell = super. tableView ( tableView, cellForRowAt: indexPath)
82
- let row = tableContents [ indexPath. section] . rows [ indexPath. row]
83
- if row. title == " Empty section title " {
84
- // Alter the cells created by QuickTableViewController
85
- cell. imageView? . image = #imageLiteral( resourceName: " iconmonstr-x-mark " )
86
- }
88
+ // Alter the cells created by QuickTableViewController
87
89
return cell
88
90
}
89
91
90
- // MARK: - UITableViewDelegate
91
-
92
- override func tableView( _ tableView: UITableView , didSelectRowAt indexPath: IndexPath ) {
93
- if let row = tableContents [ indexPath. section] . rows [ indexPath. row] as? OptionRow {
94
- row. isSelected = !row. isSelected
95
- row. action ? ( row)
96
- tableView. reloadRows ( at: [ indexPath] , with: . automatic)
97
- tableView. deselectRow ( at: indexPath, animated: true )
98
- } else {
99
- super. tableView ( tableView, didSelectRowAt: indexPath)
100
- }
101
- }
102
-
103
92
// MARK: - Private Methods
104
93
105
94
private func didToggleSelection( _ sender: Row ) {
106
- if let row = sender as? OptionRow {
107
- let state = " \( row. title) is toggled = \( row. isSelected) "
108
- print ( state)
109
- showDebuggingText ( state)
95
+ guard let option = sender as? OptionRow else {
96
+ return
110
97
}
98
+
99
+ let state = " \( option. title) is " + ( option. isSelected ? " selected " : " deselected " )
100
+ print ( state)
101
+ showDebuggingText ( state)
111
102
}
112
103
113
104
private func didToggleSwitch( _ sender: Row ) {
@@ -136,8 +127,9 @@ internal final class ViewController: QuickTableViewController {
136
127
}
137
128
138
129
private func showDebuggingText( _ text: String ) {
139
- debuggingSection. footer = text
140
- tableView. reloadSections ( [ tableContents. count - 1 ] , with: . automatic)
130
+ debugging. footer = text
131
+ let indexSet : IndexSet ? = tableContents. index ( where: { $0 === debugging } ) . map { [ $0] }
132
+ tableView. reloadSections ( indexSet ?? [ ] , with: . fade)
141
133
}
142
134
143
135
}
0 commit comments