0

我正在尝试从一个 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))
            }
        }
    }
}
4

2 回答 2

0

不要放入NavigationLinkaButton将解决您的问题:

 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))
        }
    }
于 2019-12-07T00:37:16.880 回答
0

如果要使用按钮,则将导航链接移至背景。

struct MusicButton: View {

    @State var isActive = false

    var body: some View {
        NavigationView {
        Button(action: {
            isActive.toggle()
        })
        { Image(systemName: "music.note.list")
            .resizable()
            .foregroundColor(Color.white)
            .frame(width: 25, height: 25, alignment: .center)
            .aspectRatio(contentMode: .fit)
            .font(Font.title.weight(.ultraLight))
            }
        }
        .background(
             NavigationLink(destination: PlaylistTable(), isActive: $isActive) {EmptyView()}
         )
    }
}
于 2021-08-12T13:39:09.447 回答