Reputation: 33
I am trying to use Swift UI to create an app with buttons that open a new screen when they are pressed. From looking on Google, it seems that NavigationView should be used for this. I have a NavigationView with one button. When I run the code using my iPad running IOS 13 beta, nothing seems to show on the screen. I am blind and using VoiceOver, so it is possible that the button does show but VoiceOver does not see it.
I am using VStack because I plan to have a few of these buttons AKA NavigationLinks that open another screen.
import SwiftUI
struct WindowsShortCuts: View {
var body: some View {
Text("This will show questions about Windows shortcuts.")
}
}
struct ContentView: View {
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: WindowsShortCuts()) {
Text("Windows shortcuts")
}.navigationBarTitle(Text("Choose category"))
}
}
}
}
I expect there to be a button labeled "Windows shortcuts." When I tap on the button, I expect it to open another screen. Since I am testing, the screen should have some text.
Upvotes: 1
Views: 866
Reputation: 59
Instead of using NavigationLink(destination: WindowsShortCuts())
, You should use
NavigationButton(destination: WindowsShortCuts()) {
Text("Windows shortcuts")
}.navigationBarTitle(Text("Choose category"))
I hope this will help you.
Updated answer
This is how it looks like -
struct ContentView : View {
var body: some View {
NavigationView {
VStack {
NavigationButton(destination: WindowsShortCuts()) {
Text("Window shortcut")
}.navigationBarTitle(Text("Choose category"))
}
}
}}
struct WindowsShortCuts: View {
var body: some View {
Text("This will show questions about Windows shortcuts.")
}}
Upvotes: 0