我正在尝试从一个SwiftUI视图转到另一个SwiftUI视图,并且按照下面的代码使用了NavigationLink,但是我遇到了错误:无法为类型'NavigationLink <_,_>调用初始化程序',其参数类型为'(destination:PlaylistTable)'
下面是我的按钮代码,它触发了到下一个视图的链接:
struct MusicButton: View {
var body: some View {
NavigationView {
Button(action: {
NavigationLink(destination: PlaylistTable())
})
{ Image(systemName: "music.note.list")
.resizable()
.foregroundColor(Color.white)
.frame(width: 25, height: 25, alignment: .center)
.aspectRatio(contentMode: .fit)
.font(Font.title.weight(.ultraLight))
}
}
}
}
答案 0 :(得分:0)
不要将NavigationLink
放在Button
内会解决您的问题:
NavigationView {
NavigationLink(destination: PlaylistTable())
{ Image(systemName: "music.note.list")
.resizable()
.foregroundColor(Color.white)
.frame(width: 25, height: 25, alignment: .center)
.aspectRatio(contentMode: .fit)
.font(Font.title.weight(.ultraLight))
}
}