Hi,
I have very strange problem,
I have 4 Content pages, uses the same viewmodel, the process of adding new elements to the ObservableCollection is defined inside the view model,
3 of the 4 pages working perfectly and I can do "load more" and "pull to refresh" inside them,
the 4th page not working, it still blank, after debugging I found the their is an exception thrown when adding a new element to the ObservableCollection,
the exception is:
NSInternalInconsistencyException Reason: Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).
P.S: I am binding the ObservableCollection to listview item source.
P.S: again, 3 of 4 of the pages working perfectly
P.S: this problem shown after updating to latest version of Xamarin (in order to target iPhone X)
my Code is:
private async Task fillList(bool isRef = false)
{
try
{
if (articles.Count > 0)
articles.Clear();
List<Article> t = new List<Article>();
t = App.DB.getArticlesByType(articleType);
if (isRef || t == null || t.Count == 0)
{
if (articleType == 0)
t = await App.restClient.getMainArticles();
else if (articleType == 1)
t = await App.restClient.getMyListArticles();
else if (articleType == 2)
t = await App.restClient.getReadLaterArticles();
else if (articleType == 3)
t = await App.restClient.getMostReadArticles();
for (int i = 0; i < t.Count; i++)
t[i].artType = articleType;
App.DB.insertAllArticles(t);
}
headImage = t[0].Image;
headTitle = t[0].Article_title;
headCategory = t[0].Category;
headAuthor = t[0].Author;
head_is_read_later = t[0].Is_read_later == "yes" ? "yes" : "no";
headArticle = new Article()
{
Article_id = t[0].Article_id,
Article_name = t[0].Article_name,
Article_title = t[0].Article_title,
artType = articleType,
Author = t[0].Author,
Category = t[0].Category,
Content = t[0].Content,
ID = t[0].ID,
Image = t[0].Image,
Is_read_later = t[0].Is_read_later == "yes" ? "yes" : "no",
myId = -1
};
for (int j = 1 ; j < t.Count; j++)
{
t[j].myId = j + 1;
t[j].Is_read_later = (t[j].Is_read_later == null) ? "no" : t[j].Is_read_later;
this.articles.Add(t[j]); // the exception thrown in this line
}
}
catch (Exception ex)
{
//await App.Current.MainPage.DisplayAlert("خطأ", ex.Message, "موافق");
}
}