Wednesday, October 7, 2026
HomeiOS Developmentios - Crash when making an attempt to scroll utilizing ScrollViewReader in...

ios – Crash when making an attempt to scroll utilizing ScrollViewReader in a SwiftUI Listing

[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]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments