jamesmontemagno / Xamarin.Forms-PullToRefreshLayout

Pull To Refresh a ScrollView or ListView in Xamarin.Forms
218 stars 49 forks source link

iOS crashed with NSInternalInconsistencyException #68

Closed gaocan1992 closed 5 years ago

gaocan1992 commented 5 years ago

In this code snippet, I got this ex.

Models = new ObservableCollection<XXXViewModel>();
PullToRefreshLayout.ItemSource = Models;
PullToRefreshLayout.IsRefreshing = true;
 ... some async method to get data and transform data into view models ...

Models.Clear();
foreach (var model in models) {
  Models.Add(model);
}

PullToRefreshLayout.IsRefreshing = false;

NSInternalInconsistencyException Reason: Invalid update: invalid number of items in section 0. The number of items contained in and existing section after the update (1) must be equal to the number of items contained in that section before the update(4), plus or minus the number of items inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).

gaocan1992 commented 5 years ago

After search, I found this https://forums.xamarin.com/discussion/19114/invalid-number-of-rows-in-section This problem occurs because I called observableCollection.Clear() (not sure why)

Workaround:


while(observableCollection.Count > 0)
    observableCollection.RemoveAt(0);
gaocan1992 commented 5 years ago

This is happening for CollectionView only. Listview seems to work.

jamesmontemagno commented 5 years ago

I believe this is a bug with CollectionView itself. not with this control.

gaocan1992 commented 5 years ago

@jamesmontemagno Agree, any plan of fix?

gaocan1992 commented 5 years ago

I haven't found the fix in Xamarin.Forms 4.0 Release. I will raise an issue on Xamarin.Forms github

gaocan1992 commented 5 years ago

I think I found an existing issue: https://github.com/xamarin/Xamarin.Forms/issues/5793