Пример #1
0
        public void ObjectUsageTest()
        {
            var diff = new NSDiffableDataSourceSnapshot <NSNumber, NSUuid> ();

            diff.AppendSections(new NSNumber [] { NSNumber.FromNInt(1) });
            diff.AppendItems(new NSUuid [] { new NSUuid() }, NSNumber.FromNInt(1));
            Assert.That(diff.NumberOfSections, Is.GreaterThan((nint)0), "Sections");
            Assert.That(diff.GetNumberOfItems(NSNumber.FromNInt(1)), Is.GreaterThan((nint)0), "Items");
        }
Пример #2
0
        void ConfigureDataSource()
        {
            dataSource = new UICollectionViewDiffableDataSource <NSNumber, NSNumber> (collectionView, CellProviderHandler);

            // initial data
            var itemsPerSection = 5;
            var sections        = Enumerable.Range(0, 5).Select(i => NSNumber.FromInt32(i)).ToArray();

            currentSnapshot = new NSDiffableDataSourceSnapshot <NSNumber, NSNumber> ();
            var itemOffset = 0;

            foreach (var section in sections)
            {
                currentSnapshot.AppendSections(new [] { section });
                var items = Enumerable.Range(itemOffset, itemsPerSection).Select(i => NSNumber.FromInt32(i)).ToArray();
                currentSnapshot.AppendItems(items);
                itemOffset += itemsPerSection;
            }

            dataSource.ApplySnapshot(currentSnapshot, false);

            UICollectionViewCell CellProviderHandler(UICollectionView collectionView, NSIndexPath indexPath, NSObject obj)
            {
                var sectionId = currentSnapshot.SectionIdentifiers [indexPath.Section];
                var numberOfItemsInSection = currentSnapshot.GetNumberOfItems(sectionId);
                var isLastCell             = indexPath.Item + 1 == numberOfItemsInSection;

                // Get a cell of the desired kind.
                var cell = collectionView.DequeueReusableCell(ListCell.Key, indexPath) as ListCell;

                // Populate the cell with our item description.
                cell.Label.Text           = $"{indexPath.Section}, {indexPath.Row}";
                cell.SeparatorView.Hidden = isLastCell;

                // Return the cell.
                return(cell);
            }
        }