-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crash when replacing items using RealmStorage.setSection
, if amt items in new list don't match...
#62
Comments
Hey! |
OK, I'll try that. But I do have a bit more information for you. My app uses a UITabBarController. When the crash happens, the table-view isn't visible, because it's on another tab. Another VC is frontmost and visible. I just leave the observation on for the lifetime of the view-controller, and don't check whether the view is shown or hidden. |
Sounds similar to UICollectionView stuff i've seen couple of times, sometimes crash happens when reload of UICollectionView happens when it's not visible, but i don't know the underlying specifics of how and when UIKit handles that. Maybe it's not even related to Realm, but some specific methods of UITableView/UICollectionView. |
Hi! It seems that multi-section RealmStorage currently has an unfixable design flaw with no clear way to fix it on a framework level. However, with introduction of Diffable Datasources in iOS 13, which I think should become a de-facto standard in updating UITableView, this problem has a solution. It seems that with diffable datasources we don't need RealmStorage for Realm nor CoreDataStorage for CoreData in current form, because sections and items are built from snapshot update rather than from Storage. At this point, i think we can consider RealmStorage and CoreDataStorage to be soft-deprecated, since there's much better solution going forward. I encourage you to try new beta releases with support for diffable datasources in iOS 13, and hope this solution works for you. https://github.com/DenTelezhkin/DTTableViewManager/blob/master/Guides/7.0%20Migration%20Guide.md I'm going to close this issue for now, but in any case, looking forward to any feedback. |
Here's the scenario.
I have a
UITableView
. (so, no cells). I callRealmStorage.setSection
and pass in aList
. At the moment that I do this, the list has 5 items in it.My table-view updates correctly, and draws all my cells. Great! Loving it.
At some point down the road, I need to completely replace the entire contents of my table-view. So, I pass in a new
List
by callingRealmStorage.setSection
again. This time the list is empty. (I'll be making a call to a webservice to get some data back later, but initially, the list is empty).This causes
UITableView
to crash. I get a bad index exception (trying to draw the first cell, but there shoud be no cells). So, it asks for data for index-0, but there is no data, so crash.Thankfully, I found a workaround:
before calling
setSection
callrealmStorage.deleteSections(IndexSet(integer: 0))
(I only have one section).The reason this works, is because (for reasons I don't understand) calling
setSection
does not convinceUITableView
that the amount of items in the datasource has changed, butdeleteSections
does. I can tell this, becausenumberOfRowsInSection
is never called when I callsetSection
the second time. But it does get called when I delete the section, and call setSection again.If there's any better solution to this, I'd be happy to hear it.
The text was updated successfully, but these errors were encountered: