[英]NavigationLink activates when I edit text in textfield
every time I edit textfield, getSearchResult is called. 每次我编辑文本字段时,都会调用getSearchResult。 what should I do to call getSearchResult only when I press Search button? 仅当我按下搜索按钮时才应该调用getSearchResult?
part of Contentview: Contentview的一部分:
NavigationLink(destination: SearchResultList(text: setQuery(text))){
TextField("text~", text: $text)
Text("Search")
}
part of SearchResultList: 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. 不要在NavigationLink
的内容中包含TextField
。 Following code should work for you: 以下代码应为您工作:
HStack {
TextField("text~", text: $text)
NavigationLink(destination: DetailsView(tech: techCollection[0])){
Text("Search")
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.