struct PageView: View {
var body: some View {
NavigationView {
VStack {
Text("rr")
}
.navigationBarItems(
leading: Button(action: {
print("返回")
}, label: {
Text("返回")
}),
trailing: Button(action: {
print("前进")
}, label: {
Text("前进")
})
)
// 大标题
.navigationBarTitle(Text("标题"))
}
}
}
struct PageView_Preview: PreviewProvider {
static var previews: some View {
PageView()
}
}
回退 pop
struct ShowOrHiddenView: View {
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
var data:[Person] = [
Person(id: 0),
Person(id: 1),
Person(id: 2),
Person(id: 3),
Person(id: 4),
Person(id: 5),
Person(id: 6),
]
@State var showAll:Bool = false
var body: some View {
List {
Toggle(isOn: $showAll, label: {
Text(showAll ? "显示全部" : "过滤")
})
ForEach(data) { i in
if self.showAll || i.id > 2 {
Text("\(i.id)")
}
}
}
.navigationBarItems(trailing: Button(action: {
self.presentationMode.wrappedValue.dismiss()
}, label: {
Text("pop回退")
}))
}
}
网友评论