简体   繁体   English

如何使用 SwiftUI 呈现新视图?

[英]How can I present a new view with SwiftUI?

I'm developing database search app, and want to show a result view like this https://imgur.com/a/GUN6MiX .我正在开发数据库搜索应用程序,并希望显示这样的结果视图https://imgur.com/a/GUN6MiX

The actionSheet wasn't correct answer. 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)
            }
        }

To present a new view, wrap your view in a NavigationView and use a NavigationLink instead of a normal Button .要呈现新视图,请将您的视图包装在NavigationView并使用NavigationLink而不是普通的Button Put your new view in the destination parameter like NavigationLink(destination: SomeNewView()) { ... } .将您的新视图放在目标参数中,如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.

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