如何在SwiftUI中从一个视图重定向到另一个视图?

时间:2019-12-13 11:19:00

标签: swift list navigation swiftui

我正在使用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()
    }
}

3 个答案:

答案 0 :(得分:0)

使用此

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

答案 1 :(得分:0)

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

答案 2 :(得分:0)

ThemeData(
textTheme: TextTheme(
  subhead: TextStyle(color: Colors.green),
),