NSCollectionView 10.11 API ?

DavidLilleyDavidLilley USMember ✭✭✭
edited November 2015 in Xamarin.iOS

I am trying to get a small sample working using the new NSCollectionView 10.11 API trying to use the flow layout,

I have views loaded and content appeared to filled in but they appear on the top of each other and have no clue to why ?

All Views have the position of 0,0 however the scrollview appears to be correct and when changing size the values change as if they were off the page ?

Any thoughts to where I am going wrong ?

SampleProject Attached

`

public sealed class DateControllerScroller : NSScrollView
{
    public DateControllerScroller (RectangleF aFrame): base(aFrame)
    {
        this.HasVerticalScroller = true;
        this.HasHorizontalScroller = true;
        this.AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable;
        this.AutoresizesSubviews = true;
        NSCollectionView m_aCollectionView = new NSCollectionView ();
        m_aCollectionView.Frame = aFrame;
        m_aCollectionView.DataSource = new DateControllerCollectionViewSource();
        m_aCollectionView.CollectionViewLayout = new NSCollectionViewFlowLayout()
        {
            ItemSize = new SizeF(200,200),
            MinimumLineSpacing = 10,
            MinimumInteritemSpacing =10,
            ScrollDirection = NSCollectionViewScrollDirection.Vertical
        };

        this.DocumentView = m_aCollectionView;
    }
}

public class DateControllerCollectionViewSource : NSCollectionViewDataSource
{
    NSObject[] SampleValues = new NSObject[] { 
        new NSString("Item 1"),
        new NSString("Item 2"),
        new NSString("Item 3"),
        new NSString("Item 4"),
        new NSString("Item 5"),
        new NSString("Item 6")
    };

    public override NSCollectionViewItem GetItem(NSCollectionView collectionView, NSIndexPath indexPath)
    {
        return new CollectionViewItem()
        {
            RepresentedObject = SampleValues[indexPath.Item]
        };
    }
    public override int GetNumberofItems(NSCollectionView collectionView, int section)
    {
        return SampleValues.Length;
    }

    public override int GetNumberOfSections(NSCollectionView collectionView)
    {
        return 1;
    }
}

public class CollectionViewItem : NSCollectionViewItem
{
    public CollectionViewItem () : base ()
    {
        this.View = new DateView( new RectangleF(0,0,200, 200));
    }

    public override NSObject RepresentedObject
    {
        get {return base.RepresentedObject; }
        set
        {
            if (value != null)
            {
                base.RepresentedObject = value;
                NSString aString = value as NSString;
                if (aString == null)
                {
                    return;
                }
                ((DateView)this.View).Title = aString.ToString();
            }
        }
    }

    public override bool Selected
    {
        get
        {
            return base.Selected;
        }
        set
        {
            base.Selected = value;
            ((DateView)this.View).Selected = value;
        }
    }
}

`

Best Answer

Answers

Sign In or Register to comment.