列表为空时如何设置列表高度?

时间:2020-01-15 18:22:57

标签: swiftui swiftui-list

我从API获取了数据,并将其放在列表中。我的问题是,当列表中的数组全部删除时,是否可以设置固定高度?我使用环境(.defaultMinListRowHeight,80)但没有用,请帮忙。谢谢

func containedView() -> AnyView {
    switch self.selectedIndex {
   case 0:
       return AnyView(
        List(userNotifications1.userNotificationsArray) { userNotification in
        UserNotificationCellView(userNotification: userNotification,userNotifications: self.userNotifications1)
        }.environment(\.defaultMinListRowHeight, 80)
.environment(\.defaultMinListHeaderHeight, 10)

        )

   case 1:

      return AnyView(           
        List {
            ForEach(managerNotifications, id: \.id) { (managernotification) in
                ManagerNotificationCellView(managerNotification : managernotification)

            }.onDelete(perform: self.deleteManagerNotification)
        }
    )

   default:
    return AnyView(Text("22").padding(40))
    }

when list has data, the cell's height are bigger when list is empty,the cell's height was small

1 个答案:

答案 0 :(得分:0)

确保将环境变量设置在正确的位置。下面经过测试的可与Xcode 11.2 / iOS 13.2一起使用

enter image description here

List {
  // ... list content here
}
.environment(\.defaultMinListRowHeight, 80) // << should be for List