@@ -30,9 +30,17 @@ import Weakify
3030
3131internal final class ViewController : QuickTableViewController {
3232
33+ private final class CustomCell : UITableViewCell { }
34+
3335 // MARK: - Properties
3436
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: [ ] )
3644
3745 // MARK: - UIViewController
3846
@@ -62,52 +70,35 @@ internal final class ViewController: QuickTableViewController {
6270 ] , footer: " UITableViewCellStyle.Value2 hides the image view. " ) ,
6371
6472 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+ } )
6677 ] ) ,
6778
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
7581 ]
7682 }
7783
7884 // MARK: - UITableViewDataSource
7985
8086 override func tableView( _ tableView: UITableView , cellForRowAt indexPath: IndexPath ) -> UITableViewCell {
8187 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
8789 return cell
8890 }
8991
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-
10392 // MARK: - Private Methods
10493
10594 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
11097 }
98+
99+ let state = " \( option. title) is " + ( option. isSelected ? " selected " : " deselected " )
100+ print ( state)
101+ showDebuggingText ( state)
111102 }
112103
113104 private func didToggleSwitch( _ sender: Row ) {
@@ -136,8 +127,9 @@ internal final class ViewController: QuickTableViewController {
136127 }
137128
138129 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)
141133 }
142134
143135}
0 commit comments