Skip to content

Commit 0068682

Browse files
Update README.md
1 parent 6848b46 commit 0068682

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

README.md

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,50 @@ pod 'SASelectionView'
3838

3939
## [](https://github.com/srujanadicharla/SASelectionView#example) Example
4040
```swift
41-
import UIKit
41+
import SwiftUI
4242
import SASelectionView
4343

44-
class ViewController: UIViewController {
45-
46-
@IBOutlet weak var selectedOptionLabel: UILabel!
44+
struct ContentView: View {
45+
46+
@State private var selectedText = ""
4747

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+
5160
}
52-
53-
@IBAction func didTapButton(_ sender: Any) {
61+
62+
func showSelectionView() {
5463
var sections = [SectionItem]()
5564
sections.append(SectionItem(title: "Texas", options: ["Dallas", "Houston", "Austin", "San Antonio"]))
5665
sections.append(SectionItem(title: "California", options: ["Los Angeles", "San Francisco", "Sacramento", "San Diago"]))
5766
sections.append(SectionItem(title: "New York", options: ["New York City", "Albany", "Buffalo"]))
5867
sections.append(SectionItem(title: "Florida", options: ["Miami", "Orlando", "Jacksonville", "Key West"], disabledIndices: [3:[1,3]]))
59-
68+
6069
SASelectionView.show(title: "Locations", sections: sections, showSearchBar: true, emptySearchRowTitle: "Item not found. Add this ...", emptyRowHandler: { (notFoundText) in
6170
print("Not found result: \(notFoundText)")
62-
self.selectedOptionLabel.text = notFoundText
71+
self.selectedText = notFoundText
6372
}) { (section, row, value) in
64-
self.selectedOptionLabel.text = "\(value), \(sections[section].title ?? "")"
73+
self.selectedText = "\(value), \(sections[section].title ?? "")"
6574
}
6675
}
6776
}
77+
78+
#if DEBUG
79+
struct ContentView_Previews: PreviewProvider {
80+
static var previews: some View {
81+
ContentView()
82+
}
83+
}
84+
#endif
6885
```
6986

7087
<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

Comments
 (0)