WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

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()

      }
  }

   

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

   

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

   

Save 50% in my Black Friday sale.

SAVE 50% To celebrate WWDC22, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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

Reply to this topic…

You need to create an account or log in to reply.

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.