This is a migrated thread and some comments may be shown as answers.
RadListView iOS empty List error
3 Answers 24 Views
This is a migrated thread and some comments may be shown as answers.
john
Top achievements
Rank 1
john asked on 12 Dec 2017, 12:21 PM

Hi there I am using the RadListView for Xamarin Forms and I'm encountering an error on iOS specifically.

In my scenario I give the user the option to remove a record from the list.

When I remove the last user from the collection bound to the list view I receive this error:

 

Xamarin.iOS: Received unhandled ObjectiveC exception: NSRangeException *** -[__NSArrayM objectAtIndexedSubscript:]: index 0 beyond bounds for empty array.

 

So it seems that the list view tries to view the first record of an empty list when the list is empty.

This issue is not occurring in my Android implementation.

Is there any solution to this issue.

Thanks for the help,

 

John

3 Answers, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 12 Dec 2017, 07:12 PM
Hello John,

I am not able to reproduce the issue. Run my attached demo and click the ToolbarItem to remove items from the bound ObservableCollection.

If this demo doesn't help you identify the issue, please update the attached demo so that it reproduces it and reply back with the modifications so I can investigate further.

Also include the following information:

- UI for Xamarin
- Xamarin.Forms version
- Target iOS version (simulator or device?)


Support Ticket

I recommend opening a Support Ticket here and attaching your modified project.  However, I see that you've never had a license for UI for Xamarin, so you won't be able to open a ticket as we use a per-developer license system. The developer who uses the product needs to be assigned to that license and is the one who can interact with Support system.

Are you using the product via your employer? This is a common scenario and we provide an easy way to handle it, the license owner can assign you as the Licensed User by going to the Manage Licensed Users portal.

It only takes about 30 seconds to make you the developer for the license, here are the steps:

1 - Go to the Manage Licensed Users portal
2 - Unassign the current Licensed User (this is likely the person who purchased it)
3 - Assign you as the Licensed User

Important Note: Don't worry about step #2, the company will retain ownership of the license and can re-assign the Licensed User at any time.

Once you're the licensed user, you can use UI for Xamarin and leverage the support package that comes with it.

Regards,
Lance | Tech Support Engineer, Sr.
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
john
Top achievements
Rank 1
answered on 18 Jan 2018, 10:30 AM

Hi Lance,

 

Apologies for the late reply.

Below is the code I am currently using.

I have tried to catch more on the issue using a try catch.

Again this method works without issue on Android this is specifically an iOS issue,

Telerik UI for Xamarin Version: v2018.1.117.5

 

async void ExecuteRemoveUserCommandAsync(UserDto user)
        {
            if (user != null)
            {
                if (SelectedUsers.Count > 0 && SelectedUsers.Contains(user))
                {
                    try
                    {
                        var index = SelectedUsers.IndexOf(user);
                        SelectedUsers.RemoveAt(index);
                    }
                    catch (Exception e)
                    {
                        await _prismServicesProvider.PageDialogService.DisplayAlertAsync("Error", e.Message, "Ok");
                    }
                    
                }
               
            }
        }
0
Lance | Manager Technical Support
Telerik team
answered on 18 Jan 2018, 04:34 PM
Hello John,

Thank you for providing the code. Try the following instead:

async void ExecuteRemoveUserCommandAsync(UserDto user)
{
    if (user != null)
    {
        if (SelectedUsers?.Contains(user))
        {
            try
            {
                SelectedUsers.Remove(user);
 
                //var index = SelectedUsers.IndexOf(user);
                //SelectedUsers.RemoveAt(index);
            }
            catch (Exception e)
            {
                await _prismServicesProvider.PageDialogService.DisplayAlertAsync("Error", e.Message, "Ok");
            }
        }
    }
}


This isn't directly related to UI for Xamarin so I can't say exactly why this is happening and without a reproducible to debug directly I don't have a direction to point you in. My suspicion is that the SelectedUsers collection is empty when you try to remove an item at index 0.

"index 0 beyond bounds for empty array"

So, by using the Remove() option, you won't cause an exception, however it may hide a more serious bug in the code where the SelectedUsers collection is not being populated in time.

Regards,
Lance | Tech Support Engineer, Sr.
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Asked by
john
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
john
Top achievements
Rank 1
Share this question
or