Horizontal scrollview is not working swiftUI

╄→尐↘猪︶ㄣ 提交于 2020-02-25 05:25:11

问题


i'm trying to show some horizontal view but it's not working. below are the code i'm using.

@State var userDataList = [UserModel]()
    var body: some View{
            VStack(spacing: 10){
                VStack{
                    prefView()
                        .padding(.bottom, 30)
                    Text("Tap to start making friend")
                }
                ScrollView(.horizontal, content: {
                    HStack(spacing: 10) {
                        ForEach(userDataList) { user in
                            NavigationLink(destination: ChatView(chatMember: self.chatmember, user: user)){
                                SearchUser()
                            }
                        }
                    }
                    .padding(.leading, 10)
                })
                    .frame(width: 300, height: 400)

            Spacer()
        }
        .navigationBarTitle("Profile",displayMode: .inline)
        .onAppear {
            self.userList()
        }
    }

But if i change the above code with below than it work i don't know how please help me.

ScrollView(.horizontal, content: {
                HStack(spacing: 10) {
                    ForEach(0..< 2) { index in
                        NavigationLink(destination: ChatView(chatMember: self.chatmember, user: user)){
                            SearchUser()
                        }
                    }
                }
                .padding(.leading, 10)
            })

Thanks in advance


回答1:


just for remove this line :

.frame(width: 300, height: 400)

and set frame for row view or Hstack



来源:https://stackoverflow.com/questions/60250383/horizontal-scrollview-is-not-working-swiftui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!