【发布时间】:2020-11-13 03:56:05
【问题描述】:
我有这个列表:
struct SignInList: View {
@ObservedObject var model:SignInModel
var body: some View {
List(model.currentSignIns) { signIn in
SignInRow(description: signIn)
}
}
}
使用此列表行:
struct SignInRow: View, Identifiable {
let id = UUID()
let description: SignInDescription
var body: some View {
VStack {
ButtonView(view: description.button)
}
}
}
// Map a UIView to a View. Will be using this to hold a UIView based sign-in button
// https://developer.apple.com/tutorials/swiftui/creating-and-combining-views
struct ButtonView: UIViewRepresentable {
let view: UIView
func makeUIView(context: Context) -> UIView {
return view
}
func updateUIView(_ uiView: UIView, context: Context) {
}
}
但是当我滚动列表时,列表的单元格消失了:
如果我将列表单元格更改为纯 SwiftUI,例如,
struct SignInRow: View, Identifiable {
let id = UUID()
let description: SignInDescription
var body: some View {
VStack {
Rectangle()
}
}
}
我没有得到这个效果。滚动时单元格不会消失。
我已经尝试了一些关于 SO 的想法(例如,SwiftUI and ScrollView: Views Disappear After Device Rotation 和 Content in scrollview as a list item disappears when scrolling (swiftui), why?),但到目前为止没有真正的改进。 (当我在 ScrollView 中嵌入 ForEach 时,我遇到了不同的问题 - 我的两行中只显示了一个,并且按钮不再可点击)。
【问题讨论】: