Mencoba membuat aliran tampilan orientasi dengan bidang teks untuk mengambil data profil dan pada tampilan terakhir saya akan menyimpan data di Firestore. Namun, perlu meneruskan semua data ke tampilan terakhir untuk mendaftarkan pengguna dengan data ini.

Tampilan 0 memiliki Nama pengguna, email, dan kata sandi Tampilan 1 memiliki nama depan, nama belakang, dan gambar Tampilan 2 memiliki Jabatan, nama perusahaan

Saya dapat meneruskan nama pengguna, email, dan sandi ke tampilan 1 dan nama depan, nama belakang, dan gambar ke tampilan 2.

Saya TIDAK dapat meneruskan gambar ke tampilan 3 karena sekarang gambar tersebut mengikat dan meminta argumen di "Pratinjau" yang tidak dapat saya pahami.

Binding String yang saya lewati dengan .constant("") TAPI apa yang harus saya lakukan untuk meneruskan gambar lihat kode di bawah ini.

```
import SwiftUI

    struct Step1: View {
        @State var firstname = ""
        @State var lastname = ""
        @Binding var email: String
        @Binding var password:String
        @Binding var username: String
        @State var image: Image?
        @State var showImagePicker = false
        @State private var selectedImage: UIImage?
        var body: some View {
            VStack{
            HStack{
                VStack(alignment: .leading, spacing: 4) {
                Text("Create profile")
                    .font(.system(size: 30))
                    .fontWeight(.bold)
            Text("Basic profile information")
                .font(.system(size: 18))
            }
                .padding(.horizontal, 32)
                .padding(.bottom, 50)
                .padding(.top, 50)
                Spacer()
            }

            
            VStack(spacing: 20){
                
                HStack{

                        if image != nil {
                            image?
                                .resizable()
                                .scaledToFill()
                                .frame(width: 80, height: 80)
                                .clipShape(RoundedRectangle(cornerRadius: 10.0))
                                    
                        } else {
                        Image("upload")
                            .resizable()
                            .scaledToFill()
                            .frame(width: 80, height: 80)
                            .clipShape(RoundedRectangle(cornerRadius: 10.0))
                    }
                    Spacer()
                    
                    }
                .onTapGesture {
                    self.showImagePicker = true
                }
                
            
                CustomTextField(text: $firstname, placeholder: Text("First name"), ImageName: "person")
                    .padding()
                    .background(Color(#colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 0.2611568921)))
                    .cornerRadius(10)
                    
                    CustomTextField(text: $lastname, placeholder: Text("Last name"), ImageName: "person")
                        .padding()
                        .background(Color(#colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 0.2611568921)))
                        .cornerRadius(10)
      
            }
            .padding(.horizontal, 32)
        

            Spacer()
            
            NavigationLink(
                destination: Step2(firstname: $email, lastname: $password, email: $username, password: $firstname, username: $lastname, image: $image)
                    .navigationBarBackButtonHidden(true)
                    .navigationTitle("")
                    .navigationBarHidden(true),
                label: {
                    Text("Sign Up")
                        .font(.headline)
                        .foregroundColor(.white)
                        .frame(width:360, height: 50)
                        .background(Color(#colorLiteral(red: 0.03573478386, green: 0.4008729458, blue: 0.7616711259, alpha: 1)))
                        .cornerRadius(10)
                        .padding()
                            
                        Spacer()
                    })
            
            .navigationTitle("")
            .navigationBarHidden(true)
            
        }.sheet(isPresented: $showImagePicker, onDismiss: loadImage) {
            ImagePicker(image: self.$selectedImage)
        }
    }
    
    func loadImage() {
        guard let selectedImage = selectedImage else { return }
        image = Image(uiImage: selectedImage)
    }
}


struct Step1_Previews: PreviewProvider {
    static var previews: some View {
        Step1(email: .constant(""), password: .constant(""), username: .constant(""))
    }
}
```

  
 
```
import SwiftUI

struct Step2: View {
    @Binding var firstname: String
    @Binding var lastname: String
    @Binding var email: String
    @Binding var password:String
    @Binding var username: String
    @Binding var image: Image?
    
    var body: some View {
        VStack{

            HStack{
                VStack(alignment: .leading, spacing: 4) {
                Text("Create profile")
                    .font(.system(size: 30))
                    .fontWeight(.bold)
            Text("Basic profile information")
                .font(.system(size: 18))
            }
                .padding(.horizontal, 32)
                .padding(.bottom, 50)
                .padding(.top, 50)
                Spacer()
            }

            
            VStack(spacing: 20){
                
            
                CustomTextField(text: $firstname, placeholder: Text("First name"), ImageName: "person")
                    .padding()
                    .background(Color(#colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 0.2611568921)))
                    .cornerRadius(10)
                    
                    CustomTextField(text: $lastname, placeholder: Text("Last name"), ImageName: "person")
                        .padding()
                        .background(Color(#colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 0.2611568921)))
                        .cornerRadius(10)
      
            }
            .padding(.horizontal, 32)
        

            Spacer()
            
           
            
            .navigationTitle("")
            .navigationBarHidden(true)
            
        }
        }
    }


struct Step2_Previews: PreviewProvider {
    static var previews: some View {
        Step2(firstname: .constant(""), lastname: .constant(""), email: .constant(""), password: .constant(""), username: .constant(""), image: WHAT TO PUT HERE????)
    }
}
```
1
Kevin 12 Mei 2021, 11:27

1 menjawab

Jawaban Terbaik

Anda dapat menggunakan .constant(Image(uiImage: UIImage())) atau mengatur gambar statis seperti ini .constant(Image("image_name")))

1
Raja Kishan 12 Mei 2021, 08:59