2727import UIKit
2828import ICInputAccessory
2929
30- class ExampleViewController : UIViewController , UITableViewDataSource {
31-
32- private( set) lazy var tableView : UITableView = {
33- let _tableView = UITableView ( frame: . zero, style: . Grouped)
34- _tableView. registerClass ( ExampleCell . self, forCellReuseIdentifier: NSStringFromClass ( ExampleCell . self) )
35- _tableView. allowsSelection = false
36- _tableView. dataSource = self
37- return _tableView
38- } ( )
30+ class ExampleViewController : UITableViewController {
3931
4032 private let types : [ UIView . Type ] = [
4133 ICKeyboardDismissTextField . self,
@@ -46,30 +38,28 @@ class ExampleViewController: UIViewController, UITableViewDataSource {
4638 // MARK: - Initialization
4739
4840 convenience init ( ) {
49- self . init ( nibName : nil , bundle : nil )
41+ self . init ( style : . Grouped )
5042 title = " ICInputAccessory "
5143 }
5244
5345 // MARK: - UIViewController
5446
5547 override func loadView( ) {
5648 super. loadView ( )
57- view. addSubview ( tableView)
58- tableView. frame = view. bounds
59- tableView. autoresizingMask = [ . FlexibleWidth, . FlexibleHeight]
49+ tableView. registerClass ( ExampleCell . self, forCellReuseIdentifier: NSStringFromClass ( ExampleCell . self) )
6050 }
6151
6252 // MARK: - UITableViewDataSource
6353
64- func numberOfSectionsInTableView( tableView: UITableView ) -> Int {
54+ override func numberOfSectionsInTableView( tableView: UITableView ) -> Int {
6555 return types. count
6656 }
6757
68- func tableView( tableView: UITableView , numberOfRowsInSection section: Int ) -> Int {
58+ override func tableView( tableView: UITableView , numberOfRowsInSection section: Int ) -> Int {
6959 return 1
7060 }
7161
72- func tableView( tableView: UITableView , titleForHeaderInSection section: Int ) -> String ? {
62+ override func tableView( tableView: UITableView , titleForHeaderInSection section: Int ) -> String ? {
7363 switch types [ section] {
7464 case is ICKeyboardDismissTextField . Type :
7565 return " Dismiss Keyboard "
@@ -82,7 +72,7 @@ class ExampleViewController: UIViewController, UITableViewDataSource {
8272 }
8373 }
8474
85- func tableView( tableView: UITableView , cellForRowAtIndexPath indexPath: NSIndexPath ) -> UITableViewCell {
75+ override func tableView( tableView: UITableView , cellForRowAtIndexPath indexPath: NSIndexPath ) -> UITableViewCell {
8676 let cell = tableView. dequeueReusableCellWithIdentifier ( NSStringFromClass ( ExampleCell . self) , forIndexPath: indexPath)
8777 switch types [ indexPath. section] {
8878 case let type as ICKeyboardDismissTextField . Type :
@@ -92,6 +82,10 @@ class ExampleViewController: UIViewController, UITableViewDataSource {
9282 textField. placeholder = String ( type)
9383 ( cell as? ExampleCell ) ? . showcase = textField
9484
85+ case let type as CustomizedTokenField . Type :
86+ cell. textLabel? . text = String ( type)
87+ cell. accessoryType = . DisclosureIndicator
88+
9589 case let type as ICTokenField . Type :
9690 let container = UIView ( frame: cell. bounds)
9791 let tokenField = type. init ( )
@@ -101,13 +95,22 @@ class ExampleViewController: UIViewController, UITableViewDataSource {
10195 container. addSubview ( tokenField)
10296 ( cell as? ExampleCell ) ? . showcase = container
10397
104- case let type as CustomizedTokenField . Type :
105- ( cell as? ExampleCell ) ? . showcase = type. init ( )
106-
10798 default :
10899 break
109100 }
110101 return cell
111102 }
112103
104+ // MARK: - UITableViewDelegate
105+
106+ override func tableView( tableView: UITableView , shouldHighlightRowAtIndexPath indexPath: NSIndexPath ) -> Bool {
107+ return types [ indexPath. section] == CustomizedTokenField . self
108+ }
109+
110+ override func tableView( tableView: UITableView , didSelectRowAtIndexPath indexPath: NSIndexPath ) {
111+ if types [ indexPath. section] == CustomizedTokenField . self {
112+ presentViewController ( UINavigationController ( rootViewController: CustomizedTokenViewController ( ) ) , animated: true , completion: nil )
113+ }
114+ }
115+
113116}
0 commit comments