[英]How can I present a new view with SwiftUI?
我正在开发数据库搜索应用程序,并希望显示这样的结果视图https://imgur.com/a/GUN6MiX 。
actionSheet 不是正确的答案。
HStack {
TextField("SearchText", text: $text)
.background(Color.white)
.shadow(radius: 10.0)
.foregroundColor(.black)
.padding(.trailing, -7)
Button(action: {
let r = getSearchResult(query: self.text)
if r is Int {
print("ErrorCode: \(r as! Int)")
} else {
self.holder.r = Result(sSearchResult: r as! SearchResult)
}
}){
Text("Search")
.font(.system(size: 10))
.foregroundColor(.white)
.padding(.leading, 3)
.padding(.trailing, 3)
}
}
要呈现新视图,请将您的视图包装在NavigationView
并使用NavigationLink
而不是普通的Button
。 将您的新视图放在目标参数中,如NavigationLink(destination: SomeNewView()) { ... }
。
NavigationView {
HStack {
TextField("SearchText", text: $text)
.background(Color.white)
.shadow(radius: 10.0)
.foregroundColor(.black)
.padding(.trailing, -7)
NavigationLink(destination: SomeView()) {
Text("Search")
.font(.system(size: 10))
.foregroundColor(.white)
.padding([.leading, .trailing], 3)
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.