I'm developing a Xamarin Forms app that asynchronously gets updated models from the server that need to be merged into the information shown in the UI. I accomplish this by having my viewmodels subscribe to a MessagingCenter topic to which the updated models are broadcasted. When the viewmodels receive the message, they merge in the updated data, and it appears in the UI via data-binding.
This works fine on Android, but on iOS, when an update is made to the viewmodel I get this error, which crashes the app:
*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-3318.16.14/UITableView.m:1582
It seems to me like this should work, so I filed a bug on it along with a project that reproduces the problem: Xamarin bug.
Has anyone else seen this? Is there a different approach I should be taking to update the data shown in the view?
Posts
That probably is a bug, but I would suggest not trying to update the list one item at a time. Because that property is an
ObservableCollection
every change is reflected into the UI (possibly with an animation), which is going to be at best expensive. What you should do instead is replace the whole list atomically:Thanks @adamkemp. Doing it the way you suggest does avoid this crashing problem. Unfortunately, although this fix works in the sample I created, my real app is still crashing somewhere on merging in the updated data even with the fix. I must have some other problem besides this ListView update issue. This other bug isn't caught by Xamarin, so the only info I have so far is the iOS crash log:
Oh well, back to peeling the onion.
That stack is useless without symbols and the console output.
Yes, sorry about that. After poking around I found that in a custom renderer I was making UI calls without using InvokeOnMaintThread. Since fixing that I haven't seen this bug, so for lack of better proof I'm assuming that fixed the problem.