我有一个水平图像列表。在导航栏中还有一个小的配置文件/设置按钮。当您单击配置文件按钮时,图纸视图会向上滑动,而将其关闭时,列表似乎会丢失它的单元格(基本上是其他图像的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加载的图像。
在工作表图像之前:
工作表关闭后的图像:
[我假设categories
中的List
并不多(应该不多),所以最简单的就是强制重建列表(假设您在ExploreRow.init
中的内容不多,例如] >
List { ForEach(0..<self.categories.count) { ExploreRow(title: self.categories[$0]) }.id(UUID()) } .navigationBarTitle("Justview")
*这个问题是由于List的缓存重用行视图所致。