SwiftUI:关闭工作表后,列表数据消失

问题描述 投票:0回答:1

我有一个水平图像列表。在导航栏中还有一个小的配置文件/设置按钮。当您单击配置文件按钮时,图纸视图会向上滑动,而将其关闭时,列表似乎会丢失它的单元格(基本上是其他图像的HStacks)]

这是显示工作表和列表的代码

    var body: some View {
        NavigationView {
            List {
                ForEach(0..<self.categories.count) {
                    ExploreRow(title: self.categories[$0])
                }
            }
            .navigationBarTitle("Justview")
            .navigationBarItems(trailing: profileButton)
            .sheet(isPresented: self.$showingProfile) {
                Text("User Profile: \(self.userData.userProfile.username)")
            }
        }
    }

ExploreRow本质上是滚动视图中的水平堆栈,用于显示从Web加载的图像。

在工作表图像之前:

enter image description here

工作表关闭后的图像:

enter image description here

ios swift listview swiftui reload
1个回答
0
投票

[我假设categories中的List并不多(应该不多),所以最简单的就是强制重建列表(假设您在ExploreRow.init中的内容不多,例如] >

List {
    ForEach(0..<self.categories.count) {
        ExploreRow(title: self.categories[$0])
    }.id(UUID())
}
.navigationBarTitle("Justview")

*这个问题是由于List的缓存重用行视图所致。

© www.soinside.com 2019 - 2024. All rights reserved.