Hi there,
I am still quite new to Swift. Is there a easy way to search a list with navigation links to other swift pages?
Thank you so much for your help!
Laurin
You should post code, it would be easier to explain.
But here is a simple example to explain the principles that you should adapt (by changing the List)
struct DataView: View {
var body: some View {
Text("DataView")
}
}
struct Data2View: View {
var body: some View {
Text("Data2View")
}
}
public var countrylist = ["test1", "test2", "test3"]
struct testView: View {
var countries: [String] {
let lcCountries = listOfCountry.map { $0.lowercased() }
return searchText == "" ? lcCountries : lcCountries.filter {
$0.contains(searchText.lowercased())
}
}
private var listOfCountry = countrylist
@State var searchText = ""
var body: some View {
NavigationView {
List {
ForEach(countries, id: \.self) { country in
HStack {
Text("")
Section(header: Text(country.capitalized))
{
Text("test")
}
if country.contains("test1") {
NavigationLink(destination: DataView()) {
Spacer()
Image(systemName: "percent")
}
} else if country.contains("test2"){
NavigationLink(destination: Text("test")) {
Text("test2")
}
} else if country.contains("test3"){
NavigationLink(destination: Data2View()) {
Text("test3")
}
}
}
}
}
.searchable(text: $searchText)
.navigationTitle("testview")
.navigationBarTitleDisplayMode(.inline)
}
}
}