我希望iPad在侧栏中显示我的第一个view1列表,并在旁边显示第二个视图,该视图由view1中选择的内容填充。然后,当从view2列表中选择某项时。全屏进入第三个视图。
在我的简单示例中,在加载时,我只得到一个带有“ 显然是做错了什么。感谢帮助。 我的例子:struct firstView: View {
let myFirstArray = [
"First",
"Second",
"Third"
]
var body: some View {
NavigationView {
List(myFirstArray, id: \.self) { value in
NavigationLink (destination: SecondView()) {
Text("FirstView \(value)")
}
.navigationBarTitle("First View", displayMode: .inline)
}
}
}
}
struct SecondView: View {
let mySecondArray = [
"One",
"Two",
"Three"
]
var body: some View {
List (mySecondArray, id: \.self) { value in
NavigationLink (destination: ThirdView()) {
Text("Second View \(value)")
}
}
}
}
struct ThirdView: View {
var body: some View {
Text("Hello World")
}
}
答案 0 :(得分:0)
您需要为双列导航视图样式提供默认的详细视图(对于iPad,这是默认设置-纵向/横向的侧边栏可见性不同)
var body: some View {
NavigationView {
List(myFirstArray, id: \.self) { value in
NavigationLink (destination: SecondView()) {
Text("FirstView \(value)")
}
.navigationBarTitle("First View", displayMode: .inline)
}
SecondView() // << here !!
}
}