我点击选择器它会打开屏幕上的元素列表,我们可以添加搜索栏吗?
我实现了国家选择器,在国家列表中我显示国家名称和国家代码,所以在该列表屏幕上添加搜索栏很容易找到国家。
struct ContentView: View {
//All Country get from the plist with country Code and Coutnry Name.
let countyList = Country().getAllCountyInfo()
// Selected Country
@State private var selectedCountry = 0
var body: some View {
NavigationView {
Form {
Picker(selection: $selectedCountry, label: Text("Country")) {
ForEach(countyList) { country in
HStack{
Text(country.countryName ?? "")
Spacer()
Text(country.countryCode ?? "")
}
}
}
}
.navigationBarTitle("Select country picker")
}
}
}
通过运行上面的代码,它将打开一个国家列表,如上面的屏幕。
在上面的屏幕上(国家列表)。
如何添加搜索栏来过滤国家数据?
