[ad_1]
I’m attempting to scroll to a newly appended view in a SwiftUI Listing utilizing ScrollViewReader however hold crashing with EXC_BAD_INSTRUCTION in scrollTo(_:) after including a number of objects. I’m utilizing Xcode 14.0.1 and iOS 16.0 simulator.
Here’s a minimal demo that reveals the problem:
struct ContentView: View {
@State var objects = [Item]()
@State var scrollItem: UUID? = nil
var physique: some View {
NavigationView {
ScrollViewReader { proxy in
Listing {
ForEach(objects) { merchandise in
Textual content(merchandise.id.uuidString)
.id(merchandise.id)
}
}
.listStyle(.inset)
.onChange(of: scrollItem) { newValue in
proxy.scrollTo(newValue)
}
}
.navigationTitle("Listing Demo")
.toolbar {
Button("Add") {
addItem()
}
}
}
}
func addItem() {
objects.append(Merchandise())
scrollItem = objects.final?.id
}
}
struct Merchandise: Identifiable {
let id = UUID()
}
I can get previous the problem utilizing a ScrollView as an alternative of a Listing, however I want to use the native swipe-to-delete performance in the true undertaking.
[ad_2]
