3

On Xamarin Forms, we are implementing a custom autocomplete control based on XLabs autocomplete where we empty an observable collection of objects and fill it out again with objects corresponding to a specific search term. Then it is supposed to render perfectly the results in a listView with a dataTemplate.

What we developped works perfectly for Android but throws an error on iOS of this type : Foundation.MonoTouchException: Objective-C exception thrown. Name: 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).

Here is our code:

control._availableSuggestions.Clear();

if ( filteredSuggestions.Count > 0 ) {

foreach ( var suggestion in filteredSuggestions ) 
{ 

       control._availableSuggestions.Add(filteredSuggestions);
} 

Do you know the cause of the problem, any work around ? Thanks a lot for your inputs.

Kewin Remy
  • 501
  • 4
  • 12

3 Answers3

2

If you are using Xamarin.Forms 2.4* and you do not want to downgrade, here is the solution.

if (filteredSuggestions.Count > 0)
{
    control._availableSuggestions = new ObservableCollection<object>(filteredSuggestions);
    control._lstSuggestions.ItemsSource = control._availableSuggestions;
    control.ShowHideListbox(true);
}
else
{
    control.ShowHideListbox(false);
}
Kewin Remy
  • 501
  • 4
  • 12
1

I am facing the same issue with the version of Xamarin Forms 2.4.* The solution is to to revert back to a version of Xamarin Forms prior 2.4 like 2.3.4.270 to not have this error.

TZD77
  • 11
  • 2
0

in iOS it throws MonoTouchException exception when we work with ObservableCollection with Clear() and Add() functions of ObservableCollection. The workaround for this is,

After

Clear()

method invocation of ObservableCollection.

ReInitialise the Collection,

Result = new ObservableCollection<T>(GetNewList());