【发布时间】:2020-08-28 12:47:04
【问题描述】:
在我的代码中我有这个:
var body: some View {
NavigationView {
VStack(spacing: 0) {
ScrollView(.vertical, showsIndicators: false) {
VStack(spacing: 18) {
ScrollView(.horizontal, showsIndicators: false){
HStack(spacing: 20){
Text("teste")
.frame(height: 180)
.frame(width: 330)
.background(Color.blue)
.cornerRadius(15)
Text("teste")
.frame(height: 180)
.frame(width: 330)
.background(Color.green)
.cornerRadius(15)
Text("teste")
.frame(height: 180)
.frame(width: 330)
.background(Color.pink)
.cornerRadius(15)
}.padding(.horizontal, 12)
}
ForEach(specialtyList, id: \.type){ specialty in
NavigationLink (destination: SearchBar(item: specialty)){
VStack(spacing: 18) {
HStack{
Text(specialty.type).foregroundColor(.white)
specialty.image
.renderingMode(.original)
.resizable()
.frame(width: 35, height: 35)
}.frame(minWidth: 0, idealWidth: 350, maxWidth: .infinity)
.frame(height: 100)
}
}.padding(.horizontal)
.background(specialty.color).cornerRadius(45)
}.padding(.horizontal)
}
.padding(.top)
.padding(.bottom)
}
}.navigationBarTitle("Buscar")
}.accentColor(.black)
}
我希望,根据 ForEach 中按下的按钮,下一个视图的标题是按钮的名称。现在,每个按钮中显示的名称都是“Buscar” 我试图在 ForEach 之后和 NavigationLink 之前实现一个 NavigationView,但是 ForEach 的洞消失了。基本上,我希望按下的 Text(specialty.type) 是导航栏后退按钮的名称。有什么想法吗?
【问题讨论】:
-
请按照惯例发布有问题的更新。
标签: swift foreach navigation swiftui