Forum Xamarin.iOS


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

NScollectionview redraw issue

Jio_vkmJio_vkm INMember ✭✭

I am facing one issue with NScollectionview. When i load collection view it populates all elements. But when i scroll down it some blank area will show until i focus inside the NScollectionview. Same happens when i scroll up. I debug and found that after scrolling the Getitem calls only when i focus on the collectionview. Please help me resolve this issue.

I am developing in 10.12. I run the same application in 10.13 it works without any issue.


  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    It sounds like your code is not correctly handling recycling.

    There is a collection view sample here:

    In particular check out the delegate/data source.

    In general when collection views misbehave in Cocoa you are not returning consistent data to the framework in your datasource/delegate.

    Consider printing out the data you return to verify your data.

    Without more details / an example though people are unlikely to be able to help you here.

  • Jio_vkmJio_vkm INMember ✭✭

    Thanks ChrisHamons. I follow the same code base. Only issue is in redraw. Datasource fires only when NScollectionview got focus. Did you ever face such issue. It is difficult to find what i missed :(

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    There are a huge number of possible issues, I would start by isolating your issue. You could try creating a new XM project and just add your collection view or remove items from your application until it stops reproducing. Maybe it is an interaction with other views in your application?

    As i mentioned before "Without more details / an example though people are unlikely to be able to help you here.".

  • @Jio_vkm I faced this issue under two scenario,
    1) if I not set a frame for collection Items,
    2) in ItemSelected delegate I change the background colour for the selected item, while scrolling the background
    color will change for other view.

    solution: while scrolling GetItem() will call and arrange the items into collection view, so I set background colour at GetItem().

    `public override void ItemSelected(NSCollectionView collectionView, NSIndexPath indexPath)
    //Select Previous selected item
    var cell = collectionView.GetItem(NSIndexPath.FromItemSection(SelectedSampleIndex, 0)) as SampleItem;

                //Color for deselect item       
             cell.BackgroundColor = NSColor.White;
                //Select the curent sample
            cell = collectionView.GetItem(indexPath) as SampleItem;
                cell.BackgroundColor = NSColor.FromRgb(72, 157, 243);

    At DataSource

    ` public override AppKit.NSCollectionViewItem GetItem(NSCollectionView collectionView, Foundation.NSIndexPath indexPath)
    var cell = collectionView.MakeItem("SampleItem", indexPath) as SampleItem;

            var row = (int)indexPath.Item;
            var item = Samples[row];
            //color for label background while scrolling
            if(_sampleView.SelectedSampleIndex == row)
                cell.BackgroundColor = NSColor.FromRgb(72,157,243);
                cell.BackgroundColor = NSColor.White;

    it fix for me,

Sign In or Register to comment.