TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

NavigationLink won't pass through to view

Forums > SwiftUI

Hi all,

For the past few hours I've had difficulty trying to problem solve this bug I've been encountering. In my code, I'm trying to use a NavigationLink to connect another view; however, I keep receiving the 'missing argument for parameter in call' error. For some strange reason, SwiftUI will only let me pass a Text argument through the NavigationLink in this particular instance. On other Views I've created, my NavigationLinks have worked fine. My code is below:

struct LoginView: View {

  @EnvironmentObject var viewModel: AppViewModel
  @State var username: String = ""
  @State var password: String = ""
  var body: some View {

      NavigationView {

          VStack {
                      Spacer()

                      UserImage()
                      TextField("Username", text: $username)
                          .disableAutocorrection(true)
                          .autocapitalization(.none)
                              .padding()
                              .background(TextBoxColor)
                              .foregroundColor(.black)
                              .cornerRadius(10.0)
                              .border(Color.black, width: 1)
                              .padding(.horizontal, 30.0)
                              .padding(.vertical, 5.0)
                              .cornerRadius(10.0)
                          SecureField("Password", text: $password)
                          .disableAutocorrection(true)
                          .autocapitalization(.none)
                              .padding()
                              .background(TextBoxColor)
                              .foregroundColor(.black)
                              .border(Color.black, width: 1)
                              .padding(.horizontal, 30.0)
                              .cornerRadius(10.0)
                      Text("Forgot Password?")
                          .multilineTextAlignment(.trailing)
                          .font(.system(size: 12))
                          .offset(x: 110)
                          .padding(.all, 10.0)
                          .foregroundColor(Color(red: 1.0, green: 0.0, blue: 0.0, opacity: 1.0))

                      Button(action: {viewModel.signIn(username: username, password: password)}) {
                          LoginButtonContent()
                  }
                      .disabled(username.isEmpty || password.isEmpty)

                      Image("Divider").resizable()
                          .aspectRatio(contentMode: .fit)

                      NavigationLink(destination: CreateAccountView(), label: { CreateAccountButtonContent()})
                  }

                      Spacer()
              }
          .padding()

      }
  }

1      

Your link's destination is:

NavigationLink(destination: CreateAccountView(),  // ... snip ....

Swift wants to assemble the CreateAccountView so it can display it on screen. It seems you are NOT providing the data it requires to assemble the destination view.

Share your Journey

You just joined HackingWIthSwift today. Please share with us which day you are on in the 100 Days of SwiftUI course. This will help us know if you missed important concepts in previous lessons.

Otherwise, you may be asking for help when the answer exists in @twoStraw's excellent videos.

For example this code is a mess, and distracts from the problem you're trying to solve:

TextField("Username", text: $username)
         .disableAutocorrection(true)
         .autocapitalization(.none)
         .padding()
         .background(TextBoxColor)
         .foregroundColor(.black)
         .cornerRadius(10.0)
         .border(Color.black, width: 1)
         .padding(.horizontal, 30.0)
         .padding(.vertical, 5.0)
         .cornerRadius(10.0)

@twoStraws has an excellent lesson on how to fix this. Maybe this is a nice review? See -> Creating Custom Modifiers

1      

You have give us alot of code but assuming the error is pointing at this

NavigationLink(destination: CreateAccountView(), label: { CreateAccountButtonContent()})

The CreateAccountView() or CreateAccountButtonContent() has some properties that is reequired but we can tell as you have not post those struct

1      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.