如何将动作绑定到导航视图返回按钮?
我想将动作绑定到导航视图工具栏中的后退按钮,是否有可能?
var body: some View {
List {
ForEach(mainViewModel.items) { item in
NavigationLink(destination: EditTaskView(item: item)) {
HStack {
ListRowView(item: item)
}
}
}
}
}
I would like to bind an action to the Back button in the navigationview toolbar, is it possible?
var body: some View {
List {
ForEach(mainViewModel.items) { item in
NavigationLink(destination: EditTaskView(item: item)) {
HStack {
ListRowView(item: item)
}
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能直接绑定到后退按钮,但您可以根据状态激活导航链接本身,然后像这样监听状态值的变化。请注意,这要求您将状态设置管理为 true(不像默认初始化程序那样自动点击)
You can't bind directly to the back button, but you can have the navigation link itself be activated based on state, and then listen to the change of the state value like so. Do note that this requires that you manage the setting of state to true (no auto tap like with the default initializer)