@@ -38,33 +38,50 @@ pod 'SASelectionView'
38
38
39
39
## [ ] ( https://github.com/srujanadicharla/SASelectionView#example ) Example
40
40
``` swift
41
- import UIKit
41
+ import SwiftUI
42
42
import SASelectionView
43
43
44
- class ViewController : UIViewController {
45
-
46
- @IBOutlet weak var selectedOptionLabel: UILabel !
44
+ struct ContentView : View {
45
+
46
+ @State private var selectedText = " "
47
47
48
- override func viewDidLoad () {
49
- super .viewDidLoad ()
50
- // Do any additional setup after loading the view.
48
+ var body: some View {
49
+ VStack {
50
+ Button (action : {
51
+ self .showSelectionView ()
52
+ }) {
53
+ Text (" Show List" )
54
+ }
55
+ .padding (EdgeInsets (top : 0 , leading : 0 , bottom : 12 , trailing : 0 ))
56
+
57
+ Text (selectedText)
58
+ }
59
+
51
60
}
52
-
53
- @IBAction func didTapButton ( _ sender : Any ) {
61
+
62
+ func showSelectionView ( ) {
54
63
var sections = [SectionItem]()
55
64
sections.append (SectionItem (title : " Texas" , options : [" Dallas" , " Houston" , " Austin" , " San Antonio" ]))
56
65
sections.append (SectionItem (title : " California" , options : [" Los Angeles" , " San Francisco" , " Sacramento" , " San Diago" ]))
57
66
sections.append (SectionItem (title : " New York" , options : [" New York City" , " Albany" , " Buffalo" ]))
58
67
sections.append (SectionItem (title : " Florida" , options : [" Miami" , " Orlando" , " Jacksonville" , " Key West" ], disabledIndices : [3 : [1 ,3 ]]))
59
-
68
+
60
69
SASelectionView.show (title : " Locations" , sections : sections, showSearchBar : true , emptySearchRowTitle : " Item not found. Add this ..." , emptyRowHandler : { (notFoundText) in
61
70
print (" Not found result: \( notFoundText ) " )
62
- self .selectedOptionLabel . text = notFoundText
71
+ self .selectedText = notFoundText
63
72
}) { (section, row, value) in
64
- self .selectedOptionLabel . text = " \( value ) , \( sections[section].title ?? " " ) "
73
+ self .selectedText = " \( value ) , \( sections[section].title ?? " " ) "
65
74
}
66
75
}
67
76
}
77
+
78
+ #if DEBUG
79
+ struct ContentView_Previews : PreviewProvider {
80
+ static var previews: some View {
81
+ ContentView ()
82
+ }
83
+ }
84
+ #endif
68
85
```
69
86
70
87
<img src =" https://github.com/srujanadicharla/SASelectionView/blob/master/Images/screenshot1.png " width =" 300 " height =" 649 " ><img src =" https://github.com/srujanadicharla/SASelectionView/blob/master/Images/screenshot2.png " width =" 300 " height =" 649 " >
0 commit comments