简体   繁体   English

如何导航到不同的视图?

[英]How can I navigate to different views?

I am learning to use Swiftui and I need your help.我正在学习使用 Swiftui,我需要你的帮助。 The following pickers are present in my project:我的项目中存在以下选择器:

    Picker(selection: $selectedChoose, label: Text("Cosa ti serve?")) {
            ForEach(0 ..< choose.count) {
            Text(self.choose[$0]).tag($0)
    }
    }.pickerStyle(SegmentedPickerStyle())
            //WheelPickerStyle



    Picker(selection: $selectedCountry, label: Text("Città")) {
            ForEach(0 ..< country.count) {
            Text(self.country[$0]).tag($0)
    }
    }

    Picker(selection: $selectedAppartamento, label: Text("Tipo appartamento")) {
            ForEach(0 ..< appartamento.count) {
            Text(self.appartamento[$0]).tag($0)
    }
    }

    Picker(selection: $selectedCamera, label: Text("Tipo camera")) {
            ForEach(0 ..< camera.count) {
            Text(self.camera[$0]).tag($0)
    }
    }

At the end of the View, I have the following Text to which I will add the NavigationLink:在视图的末尾,我有以下文本,我将向其中添加 NavigationLink:

Text("Mostra annunci")
.font(Font.custom("Helvetica Neue", size: 15))
.foregroundColor(.white)
.frame(width: 150, height: 30).foregroundColor(Color.white)
.background(Color(red: 0.649, green: 0.18, blue: 0.117)).cornerRadius(10).padding(15)

Is it possible to link user choices with different views?是否可以将用户选择与不同的视图联系起来? I mean, if a user selects a different city, room type and type of apartments, how can I link these choices to different views?我的意思是,如果用户选择不同的城市、房间类型和公寓类型,我如何将这些选择链接到不同的视图? Each view should show results based on the different choices made by the user in the pickers above.每个视图都应该根据用户在上面的选择器中做出的不同选择来显示结果。 How can I do that?我怎样才能做到这一点?

Thank you in advance:)先感谢您:)

you can popup new views using the.sheet(...).您可以使用.sheet(...) 弹出新视图。 The restriction is that you can only have one of those.限制是您只能拥有其中之一。 So you would have to do something like this:所以你必须做这样的事情:

        .sheet(isPresented: $showSheet) {
            if self.selectedCountry == "myCountry" {
                Text("myCountry")
            }
            else if self.selectedCountry == "yourCountry" {
                Text("yourCountry")
            }
            ... lots of other if else

In your case I would reconsider the whole structure.在你的情况下,我会重新考虑整个结构。 Use just one sheet option and pass in the choices the user made.仅使用一个工作表选项并传递用户所做的选择。 And inside the new view present the data as chosen.在新视图中显示所选数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何导航到 swift 侧栏中的不同视图? - How to navigate to different views in a side bar in swift? 如何通过使用 @EnvironmentObject 路由视图导航到项目的详细视图? - How can I navigate to a detail view of an item by using an @EnvironmentObject to route the views? 如何通过点击 ForEach 中的按钮导航到不同的屏幕/视图 - How to navigate to different screens/views by tapping button which is in ForEach 如何使用 SwiftUI 中的按钮在视图之间导航? - How do I navigate between views using a button in SwiftUI? 在使用嵌套在 LazyVGrid 中的 ForEach 时,如何实现导航到不同视图的可用播放按钮? - While using a ForEach nested in a LazyVGrid how can I implement usable play buttons that navigate to a different view? 如何使用 swiftUI 中的按钮在视图之间导航 - how to navigate between views with buttons in swiftUI 如何在 SwiftUI 中的 IF 语句中导航视图 - How to navigate views within an IF statement in SwiftUI 如何在同一个“主”视图中切换 2 个不同的视图? SwiftUI - How can I switch 2 different views inside same “Main” view? SwiftUI SwiftUI:当同一表单上有选取器时,如何导航到 NavigationLink? - SwiftUI: How can I navigate to a NavigationLink when there is a Picker on the same Form? 如何从 SwiftUI 视图导航到 Storyboard VC? - How can I navigate to Storyboard VC from SwiftUI View?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM