BLACK FRIDAY SALE: Save 50% on all my Swift books and bundles! >>

Scrolling List in EditMode "loses" the selection that goes offscreen

Forums > SwiftUI

Hi guys,

I'm encountering an unexpected behavior when I select a bunch of cells in a List in EditMode. If I select some cells those get offscreen they get deselected when I scroll back. As far as I understand it's a 14.2-14.4 iOS bug (hopefully not 14.5) but I could not find a solution / workaround. Did you get the same behavior and if so, did you get to work properly? Thank you!


            List(selection: $selection) {
                ForEach(days, id: \.self) { day in
                    Section(header: Text(day, style: .date).font(.title3)) {
                        ForEach(scansByDate[day]!, id: \.self) { scan in
                        .onDelete { indexSet in
                            let key = scansByDate[day]![indexSet.first!]
                            if let index = modelData.scans.firstIndex(of: key) {
                                modelData.scans.remove(at: index)
                    } //end of Section
                } // end of OuterForEach
            } //end of List
            .environment(\.editMode, .constant(isEditing ? : EditMode.inactive)).animation(Animation.spring())

Console Error (sadly could not understand much):

Attempted to call -cellForRowAtIndexPath: on the table view while it was in the process of updating its visible cells, which is not allowed. Make a symbolic breakpoint at UITableViewAlertForCellForRowAtIndexPathAccessDuringUpdate to catch this in the debugger and see what caused this to occur. Perhaps you are trying to ask the table view for a cell from inside a table view callback about a specific row? Table view: <_TtC7SwiftUIP33_BFB370BA5F1BADDC9D83021565761A4925UpdateCoalescingTableView: 0x11f0c3e00; baseClass = UITableView; frame = (0 0; 428 926); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x6000018192f0>; layer = <CALayer: 0x6000016fd040>; contentOffset: {0, 74.333333333333329}; contentSize: {428, 997.33333333333337}; adjustedContentInset: {91, 0, 83, 0}; dataSource: <_TtGC7SwiftUIP10$1b47672b819ListCoreCoordinatorGVS_20SystemListDataSourceV10ScanTheBar4Scan_GOS_19SelectionManagerBoxS3___: 0x11e73d0f0>>

Screen recording of the issue:


Save 50% in my Black Friday sale.

SAVE 50% To celebrate Black Friday, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.