I'm trying to make an app using Apple's SwiftUI and I need to have two buttons that present two different views in a single List
row.
I use Xcode beta 7 and MacOS Catalina beta 7. I've tried to add a Button
that present the view but, I couldn't click it and when I tried on a simple Button
outside the List
and clicked it, the AddList()
view didn't appear. I've also tried adding a navigationButton
inside navigationButton
but it didn't work too. Adding a tapAction
doesn't work too when you click on it, the view still does not appear
NavigationView {
List(0..<5) { item in
NavigationLink(destination: ContentOfList()) {
Text("hello") // dummy text
Spacer()
Text("edit")
.tapAction {
AddList() // This is the view I want to present
}
}
}.navigationBarItems(trailing: NavigationLink(destination: AddList(), label: { // doesn't work within navigationBarItems
Image(systemName: "plus.circle.fill")
}))
}
I expect the AddList()
view to appear but in the two cases, it doesn't.
improved version. (Swift, iOS 13 beta 4)
Update: The NavigationButton was very short lived. In beta3 it is already deprecated. I am updating the code to use its replacement: NavigationLink.
You can present a view from all three places. Here's how:
Much improved version (SwiftUI, iOS 13 beta 7)
The same solution works for dismissing Modals presented with the .sheet modifier.