SwiftUI NavigationButton within navigationBarItems

2019-07-04 04:55发布

I am looking to be able to use a NavigationButton to navigate to a new view within .navigationBarItems. This is how I expect it should work:

NavigationView {
    Text("Hello world")
    .navigationBarTitle(Text("Title"))
    .navigationBarItems(trailing:
        NavigationButton(destination: TestView()) {
            Text("Next")
        }
    )
}

However, the "Next" button doesn't do anything! I am aware of PresentationButton which provides a popover view like so:

NavigationView {
    Text("Hello world")
        .navigationBarTitle(Text("Title"))
        .navigationBarItems(trailing:
            PresentationButton(destination: TestView()) {
                Text("Next")
            }
        )
}

But this isn't what I'm looking for.

标签: swift swiftui
1条回答
男人必须洒脱
2楼-- · 2019-07-04 05:52

You may use DynamicNavigationDestinationLink, I posted an answer to a very similar question in:

https://stackoverflow.com/a/56858112/7786555

查看更多
登录 后发表回答