简体   繁体   中英

NavigationLink activates when I edit text in textfield

every time I edit textfield, getSearchResult is called. what should I do to call getSearchResult only when I press Search button?

part of Contentview:

NavigationLink(destination: SearchResultList(text: setQuery(text))){
    TextField("text~", text: $text)
    Text("Search")
}

part of SearchResultList:

struct SearchResultList: View {
    @State var text: String
    @State var result = Result(sSearchResult: getSearchResult(query: query) as! SearchResult)

    var body: some View {

    }
}

Searching data every time when textfield changes causes severe speed problem

Don't include TextField in the NavigationLink 's content. Following code should work for you:

HStack {
    TextField("text~", text: $text)
    NavigationLink(destination: DetailsView(tech: techCollection[0])){
        Text("Search")
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM