skip to Main Content

I there anyway to combine a List and say Form view on the same screen? or do you have to have one or the other and manually build the rest?

I have this code, and each component the list and the form, are scrolling independently and also very spaced apart..

enter image description here


var body: some View {
        
            VStack(spacing: 0) {
                Form {
                    Text(orgEntity.name)
                    Text(orgEntity.address)
                }
                .padding([.bottom], 20)
                List {
                    ForEach(0...3, id: .self ) { int in
                        Text("List Test (int)")
                    }
                }
                .navigationTitle("(orgEntity.name)")
            }
        }
    }

2

Answers


  1. Don’t use list: place everything in the Form with Sections, like this:

    var body: some View {
                
            VStack(spacing: 0) {
                Form {
                    Section {
                        Text("Name")
                        Text("Address")
                    }
                    Section {
                        ForEach(0...10, id: .self ) { int in
                            Text("List Test (int)")
                        }
                    }
                }
                .padding([.bottom], 20)
                .navigationTitle("("Name")")
            }
        }
    
    Login or Signup to reply.
  2. If you want to keep the stationary form and still have a scrolling list then a frame(height:) can be used on the Form:

    .frame(height: 80)
    

    Result:

    enter image description here

    Example code:

    struct ComboView: View {
    
        var body: some View {
    
            VStack(spacing: 0) {
                Form {
                    Text("Name O")
                    Text("O Michigan St.")
                }
                .frame(height: 80)
                
                List {
                    ForEach(0...20, id: .self ) { int in
                        Text("List Test (int)")
                    }
                }
                .navigationTitle("Name O")
            }
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search