【问题标题】:How to redirect from one view to another view in SwiftUI?如何在 SwiftUI 中从一个视图重定向到另一个视图?
【发布时间】:2019-12-13 11:19:00
【问题描述】:

我正在使用SwiftUI。我正在尝试从列表移动到特定列表行的详细信息。我用过下面写的代码

struct StudentList: View {
    var body: some View {
        NavigationView {
            List(studentData) { student in
                NavigationLink(destination: studentDetail()) {
                    studentRow(student: student)
                }
            }
            .navigationBarTitle(Text("Student Details"))
        }
    }
}

struct StudentList_Previews: PreviewProvider {
    static var previews: some View {
        StudentsList()
    }
}

【问题讨论】:

    标签: swift list navigation swiftui


    【解决方案1】:

    使用这个

     List(studentData) { student in
         NavigationLink.init("Here Title", destination:  studentDetail())
     }   
    

    【讨论】:

      【解决方案2】:
      struct ContentView: View {
      
        let items = [1,2,3,4,5]
        var body: some View {
      
          NavigationView {
            List(items, id: \.self) { inx in
              NavigationLink(destination: DetailsView(inx: inx)) {
                  Text("\(inx)")
              }
            }
          }
        }
      }
      
      struct DetailsView: View {
          var  inx : Int
          var body: some View {
              VStack {
                  Text("\(inx)")
              }
          }
      }
      

      【讨论】:

        【解决方案3】:
         NavigationLink(destination: "provide your view here") {
        
                            } 
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-10-30
          • 2016-04-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-10-15
          相关资源
          最近更新 更多