简体   繁体   中英

In Swift UI, nothing appears to show on the screen when I use NavigationLink

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.

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.")
}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM