初始化器的结果是未得到的
我正在尝试启用点击的详细视图,以及滑动手势,以最喜欢地标。我不能使用导航链接执行相同的操作,以便对任何建议表示赞赏。我有下面附加的两个应用程序
NavigationView {
List {
Toggle(isOn: $showFavoritesOnly) {
Text("Favorites only")
}
ForEach(filteredLandmarks) { landmark in
NavigationLink {
LandmarkDetail(landmark: landmark)
}
label: {
LandmarkRow(landmark: landmark)
}
}
*/
ForEach(filteredLandmarks){ landmark in
LandmarkRow(landmark: landmark)
.swipeActions(edge:.trailing){
Button{
print("fav")
} label:{
Label("favourite",systemImage: "star.circle.fill")
}
}
.onTapGesture {
LandmarkDetail( landmark: landmark)
}
}
}
.navigationTitle("Landmarks")
}
}
I am trying to enable a detailed view on tap as well as a swipe gesture to favorite the landmark. I cannot do the same using the navigation link so that any suggestions would be appreciated. I have both the applications attached below
NavigationView {
List {
Toggle(isOn: $showFavoritesOnly) {
Text("Favorites only")
}
ForEach(filteredLandmarks) { landmark in
NavigationLink {
LandmarkDetail(landmark: landmark)
}
label: {
LandmarkRow(landmark: landmark)
}
}
*/
ForEach(filteredLandmarks){ landmark in
LandmarkRow(landmark: landmark)
.swipeActions(edge:.trailing){
Button{
print("fav")
} label:{
Label("favourite",systemImage: "star.circle.fill")
}
}
.onTapGesture {
LandmarkDetail( landmark: landmark)
}
}
}
.navigationTitle("Landmarks")
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您不能使用
ontapesture
导航到另一个view
。是由于使用
ontapesture
导航到另一个view
引起的。幸运的是,您的问题有一个解决方案。在您的第二个
foreach
循环中,将代码替换为以下代码。Firstly, you can't use
onTapGesture
to navigate to anotherView
.is caused by using
onTapGesture
to navigate to anotherView
.Fortunately, there is a solution for your problem. Inside your second
ForEach
loop, replace your code with the code below.