I am trying to to recreate what everyone know from UITableView with SwiftUI: A simple search field in the header of the tableview:
However, the List View in SwiftUI does not even seem to have a way to add a header or footer. You can set a header with a TextField to sections like this:
@State private var searchQuery: String = ""
var body: some View {
List {
Section(header:
Group{
TextField($searchQuery, placeholder: Text("Search"))
.background(Color.white)
}) {
ListCell()
ListCell()
ListCell()
}
}
}
However, I am not sure if this is the best way to do it because:
- The header does not hide when you scroll down as you know it from UITableView.
- The SearchField does not look like the search field we know and love.
Has anyone found a good approach? I don't want to fall back on UITableView.