UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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!

Code:

            List(selection: $selection) {
                ForEach(days, id: \.self) { day in
                    Section(header: Text(day, style: .date).font(.title3)) {
                        ForEach(scansByDate[day]!, id: \.self) { scan in
                            Text(scan.content)
                        }
                        .onDelete { indexSet in
                            let key = scansByDate[day]![indexSet.first!]
                            if let index = modelData.scans.firstIndex(of: key) {
                                modelData.scans.remove(at: index)
                                modelData.save()
                            }
                        }
                    } //end of Section
                } // end of OuterForEach
            } //end of List
            .listStyle(GroupedListStyle())
            .environment(\.editMode, .constant(isEditing ? EditMode.active : 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: https://gifyu.com/image/tFtO

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

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.