@@ -29,16 +29,24 @@ import ICInputAccessory
2929
3030class ExampleViewController : UITableViewController {
3131
32- private let types : [ UIView . Type ] = [
33- ICKeyboardDismissTextField . self,
34- ICTokenField . self,
35- CustomizedTokenField . self
32+ private let showcases : [ UIView . Type ] = [
33+ KeyboardDismissTextField . self,
34+ TokenField . self,
35+ CustomizedTokenField . self,
36+ OptionPickerControl< Language> . self
3637 ]
3738
39+ private lazy var languagePicker : OptionPickerControl < Language > = {
40+ let picker = OptionPickerControl < Language > ( )
41+ picker. options += Language . availableLanguages. map ( Option . init ( _: ) )
42+ picker. addTarget ( self , action: . updateLanguage, for: . valueChanged)
43+ return picker
44+ } ( )
45+
3846 private lazy var flipButton : UIButton = {
3947 let _button = UIButton ( type: . system)
4048 _button. frame = CGRect ( x: 0 , y: 0 , width: UIScreen . main. bounds. width, height: 88 )
41- _button. setTitle ( " Storyboard " , for: UIControlState ( ) )
49+ _button. setTitle ( " Storyboard " , for: UIControl . State ( ) )
4250 _button. addTarget ( self , action: . showStoryboard, for: . touchUpInside)
4351 return _button
4452 } ( )
@@ -52,42 +60,46 @@ class ExampleViewController: UITableViewController {
5260
5361 // MARK: - UIViewController
5462
55- override func loadView ( ) {
56- super. loadView ( )
63+ override func viewDidLoad ( ) {
64+ super. viewDidLoad ( )
5765 tableView. rowHeight = 44
5866 tableView. register ( ExampleCell . self, forCellReuseIdentifier: String ( describing: ExampleCell . self) )
5967 tableView. tableFooterView = flipButton
6068 tableView. tableFooterView? . isUserInteractionEnabled = true
69+ view. addSubview ( languagePicker)
6170 }
6271
6372 // MARK: - UITableViewDataSource
6473
6574 override func numberOfSections( in tableView: UITableView ) -> Int {
66- return types . count
75+ return showcases . count
6776 }
6877
6978 override func tableView( _ tableView: UITableView , numberOfRowsInSection section: Int ) -> Int {
7079 return 1
7180 }
7281
7382 override func tableView( _ tableView: UITableView , titleForHeaderInSection section: Int ) -> String ? {
74- switch types [ section] {
75- case is ICKeyboardDismissTextField . Type :
83+ switch showcases [ section] {
84+ case is KeyboardDismissTextField . Type :
7685 return " Dismiss Keyboard "
77- case is ICTokenField . Type :
86+ case is TokenField . Type :
7887 return " Text Field with Tokens "
7988 case is CustomizedTokenField . Type :
8089 return " Customize Token Field "
90+ case is OptionPickerControl < Language > . Type :
91+ return " Option Picker Control "
8192 default :
8293 return " "
8394 }
8495 }
8596
8697 override func tableView( _ tableView: UITableView , cellForRowAt indexPath: IndexPath ) -> UITableViewCell {
8798 let cell = tableView. dequeueReusableCell ( withIdentifier: String ( describing: ExampleCell . self) , for: indexPath)
99+ cell. accessoryType = . none
88100
89- switch types [ indexPath. section] {
90- case let type as ICKeyboardDismissTextField . Type :
101+ switch showcases [ indexPath. section] {
102+ case let type as KeyboardDismissTextField . Type :
91103 let textField = type. init ( )
92104 textField. leftViewMode = . always
93105 textField. leftView = UIView ( frame: CGRect ( x: 0 , y: 0 , width: 15 , height: 15 ) )
@@ -98,7 +110,7 @@ class ExampleViewController: UITableViewController {
98110 cell. textLabel? . text = String ( describing: type)
99111 cell. accessoryType = . disclosureIndicator
100112
101- case let type as ICTokenField . Type :
113+ case let type as TokenField . Type :
102114 let container = UIView ( frame: cell. bounds)
103115 let tokenField = type. init ( )
104116 tokenField. placeholder = String ( describing: type)
@@ -107,6 +119,11 @@ class ExampleViewController: UITableViewController {
107119 container. addSubview ( tokenField)
108120 ( cell as? ExampleCell ) ? . showcase = container
109121
122+ case is OptionPickerControl < Language > . Type :
123+ ( cell as? ExampleCell ) ? . showcase = nil
124+ cell. textLabel? . text = languagePicker. selectedOption. title
125+ cell. accessoryType = . disclosureIndicator
126+
110127 default :
111128 break
112129 }
@@ -116,12 +133,25 @@ class ExampleViewController: UITableViewController {
116133 // MARK: - UITableViewDelegate
117134
118135 override func tableView( _ tableView: UITableView , shouldHighlightRowAt indexPath: IndexPath ) -> Bool {
119- return types [ indexPath. section] == CustomizedTokenField . self
136+ switch showcases [ indexPath. section] {
137+ case is CustomizedTokenField . Type :
138+ return true
139+ case is OptionPickerControl < Language > . Type :
140+ return true
141+ default :
142+ return false
143+ }
120144 }
121145
122146 override func tableView( _ tableView: UITableView , didSelectRowAt indexPath: IndexPath ) {
123- if types [ indexPath. section] == CustomizedTokenField . self {
147+ switch showcases [ indexPath. section] {
148+ case is CustomizedTokenField . Type :
124149 present ( UINavigationController ( rootViewController: CustomizedTokenViewController ( ) ) , animated: true , completion: nil )
150+ case is OptionPickerControl < Language > . Type :
151+ tableView. deselectRow ( at: indexPath, animated: true )
152+ languagePicker. becomeFirstResponder ( )
153+ default :
154+ break
125155 }
126156 }
127157
@@ -134,6 +164,10 @@ class ExampleViewController: UITableViewController {
134164 }
135165 }
136166
167+ @objc fileprivate func updateLanguage( _ sender: UIControl ) {
168+ tableView. reloadData ( )
169+ }
170+
137171}
138172
139173
@@ -142,4 +176,5 @@ class ExampleViewController: UITableViewController {
142176
143177private extension Selector {
144178 static let showStoryboard = #selector( ExampleViewController . showStoryboard ( _: ) )
179+ static let updateLanguage = #selector( ExampleViewController . updateLanguage ( _: ) )
145180}
0 commit comments