如何使用 SwiftUI 呈现新视图?

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)
        }
    }
}