Multiple ListView in same Xaml throws NSRangeException in iOS

I have 3 listview in xaml, each one binded to its own list on the viewmodel, for some reason that i dont understand, if one of the list has 4 elements and the others have 3, i am unable to acess 4 element in the first one and it throws the following exception in ios : SRangeException Reason: -[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:usingPresentationValues:]: row (4) beyond bounds (4) for section (0).

Does anyone know why its forcing me to have the same number of elements in each listview? It doesnt make any sense.
They are separated listviews, they are binded to separated lists i dont understand

This is the xaml:


<ListView.ItemTemplate>




        <SearchBar x:Name="leadsSearch"  IsVisible="False" Placeholder="Busca" TextChanged="SearchBar_TextChangedLeads" HeightRequest="50"/>
        <ListView x:Name="leadsList" Margin="5" IsVisible="False" ItemsSource="{Binding Leads}" SelectedItem="{Binding LeadSeleccionado, Mode=TwoWay}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Orientation="Horizontal">
                            <Label Text="{Binding recordLabel}" VerticalTextAlignment="Center" LineBreakMode="TailTruncation"
                                   HorizontalOptions="FillAndExpand" TextColor="Black" FontSize="18"/>
                            <Image Source="llamada.png" VerticalOptions="Center" HorizontalOptions="End" HeightRequest="100" WidthRequest="50" >
                                <Image.GestureRecognizers>
                                    <TapGestureRecognizer
                                       Command="{Binding Path=BindingContext.LlamarLeadAction, Source={x:Reference Name= leadsList}}"
                                        CommandParameter="{Binding}"
                                        NumberOfTapsRequired="1" />
                                </Image.GestureRecognizers>
                            </Image>
                            <Image Source="correo.png" VerticalOptions="Center" HorizontalOptions="End" HeightRequest="100" WidthRequest="50">
                                <Image.GestureRecognizers>
                                    <TapGestureRecognizer
                                       Command="{Binding Path=BindingContext.CorreoLeadAction, Source={x:Reference Name= leadsList}}"
                                        CommandParameter="{Binding}"
                                        NumberOfTapsRequired="1" />
                                </Image.GestureRecognizers>
                            </Image>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

        <SearchBar x:Name="emprSearch" IsVisible="False" Placeholder="Busca" TextChanged="SearchBar_TextChangedEmpresas" HeightRequest="50"/>
        <ListView x:Name="empresasList" Margin="5" IsVisible="False" ItemsSource="{Binding Empresas}" 
                  ItemSelected="empresasList_ItemSelected" HasUnevenRows="True" CachingStrategy="RecycleElement">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Orientation="Horizontal">
                            <Image Source="empresa.png" Margin="10,0,10,0"/>
                            <Label Text="{Binding recordLabel}" VerticalTextAlignment="Center" LineBreakMode="TailTruncation"
                                   HorizontalOptions="FillAndExpand" TextColor="Black" FontSize="18"/>
                            <Image Source="llamada.png" VerticalOptions="Center" HorizontalOptions="End" HeightRequest="100" WidthRequest="50" >
                                <Image.GestureRecognizers>
                                    <TapGestureRecognizer
                                       Command="{Binding Path=BindingContext.LlamarEmpresaAction, Source={x:Reference Name= empresasList}}"
                                        CommandParameter="{Binding}"
                                        NumberOfTapsRequired="1" />
                                </Image.GestureRecognizers>
                            </Image>
                            <Image Source="correo.png" VerticalOptions="Center" HorizontalOptions="End" HeightRequest="100" WidthRequest="50">
                                <Image.GestureRecognizers>
                                    <TapGestureRecognizer
                                       Command="{Binding Path=BindingContext.WebEmpresaAction, Source={x:Reference Name= empresasList}}"
                                        CommandParameter="{Binding}"
                                        NumberOfTapsRequired="1" />
                                </Image.GestureRecognizers>
                            </Image>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

Best Answer

  • rikihanksrikihanks ✭✭
    Accepted Answer

    I fixed it. For anyone interested, ios is not a fan of having more of one listview in the same page, my solution was to put them in different pages and make the user believe he is in the same one by using the same UI in all of them

Answers

  • rikihanksrikihanks Member ✭✭
    Accepted Answer

    I fixed it. For anyone interested, ios is not a fan of having more of one listview in the same page, my solution was to put them in different pages and make the user believe he is in the same one by using the same UI in all of them

Sign In or Register to comment.