Learn Courses My Dashboard

Navigation view is bugging out! (IPad)

My code is not working.
Whenever I want to open a new view, it opens as a very small size.
If i make the size larger, then the “back button dissapears.
Here is the code

import SwiftUI

struct introTitle: View {

@State var CGIntroTitleSize: CGFloat = 150

@State var randomNumber = Int.random(in: 1...1000)

@State var title = "漢字学校"

class kanji{
    var kanji = ""
    var kunReading = ""
    var meaning = ""
}

var body: some View {
    VStack {
        Text("Welcome to" + title)
            .foregroundColor(.blue)
            .font(.title)
        NavigationView {
            NavigationLink(destination: introInfo()) {
                Text("Continue")
            }
        }
        .frame(width: CGIntroTitleSize, height: CGIntroTitleSize)
    }
}

}

Here is the image

If i remove the “navigation view” part, it just doesn’t work at all.

I have no idea why this is happening

What exactly are you trying to achieve?

Do you want to be able to tap on “Continue” and transition to another View and in so doing, be able to come back to the initial View? ie: from this:

To something like this:

Or do you want the second View to appear in the middle as you have shown in the screenshot?

I would like it to transfer to a second view.
I would also like to learn how to remove the “back” button if i can

I am not really sure why it’s not working

It’s because you are putting your NavigationView inside a VStack and setting a pretty small frame on it.

Instead, put the VStack inside the NavigationView. And you can probably get rid of the frame, although I’m not entirely sure what you’re trying to do with it.

You can hide the Back button by adding this modifier to the View:

.navigationBarBackButtonHidden(true)

Thank you so much!!! Although, i am not entirely sure how to remove the title, and move the navigation link to the centre.

If you want to remove the two column layout you can force the navigation view into the stacked style with this

.navigationViewStyle(StackNavigationViewStyle())