List inside ScrollView is not displayed on WatchOs

非 Y 不嫁゛ 提交于 2020-12-13 05:03:10

问题


I have a list inside a scrollview and it is not displaying below the image and the buttons. I've also tried to put the list and other items inside of a VStack and that allows me to see one item of the list at the time opposed to scrolling past the Image and buttons to show the whole list.

    ScrollView{
        Image(uiImage: self.image)
            .resizable()
            .frame(width: 80, height: 80)
            .scaledToFit()

        Text("\(name)")
            .lineLimit(2)
        HStack{
            Button(action: {
                print("button1")
            }){
                Image(systemName: "pencil")
            }
            Button(action: {
                print("button 2")
            }){
                Image(systemName: "trash")

            }
        }
        List{
            ForEach(self.items, id: \.self) { item in
                VStack{
                    Text(item.name)
                        .font(.headline)
                        .lineLimit(1)

                    Text(item.subname)
                        .font(.subheadline)
                        .lineLimit(1)
                }
            }
        }
    }
    .navigationBarTitle(Text("Tittle"))
    .edgesIgnoringSafeArea(.bottom)

Ive also tried to add .frame( minHeight: 0, maxHeight: .infinity) to the list to force it to have its whole height and that did not work either. Any suggestions or might this be a swiftUI bug ?

EDIT

I just realized Im getting this error when scrolling:

APPNAME Watch Extension[336:60406] [detents] could not play detent NO, 2, Error Domain=NSOSStatusErrorDomain Code=-536870187 "(null)", (
        {
        Gain = "0.01799999922513962";
        OutputType = 0;
        SlotIndex = 4;
    },
        {
        Gain = "0.6000000238418579";
        OutputType = 1;
        SlotIndex = 5;
    }
)

回答1:


Indicate some height for your List like

 List{
      ForEach(self.items, id: \.self) { item in
          VStack{
              Text(item.name)
                   .font(.headline)
                   .lineLimit(1)

              Text(item.subname)
                   .font(.subheadline)
                   .lineLimit(1)
          }
      }
 }.frame(minHeight: 200, maxHeight: .infinity)



回答2:


Have you tried putting the List inside of a GeometryReader and setting the frame there?



来源:https://stackoverflow.com/questions/58334210/list-inside-scrollview-is-not-displayed-on-watchos

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