UICollectionViewDataSource クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
UICollectionViewのデータ ソース。
[Foundation.Model]
[Foundation.Protocol]
[Foundation.Register("Microsoft_iOS__UIKit_UICollectionViewDataSource", false)]
public abstract class UICollectionViewDataSource : Foundation.NSObject, IDisposable, UIKit.IUICollectionViewDataSource
[Foundation.Model]
[Foundation.Protocol]
[Foundation.Register("Microsoft_MacCatalyst__UIKit_UICollectionViewDataSource", false)]
public abstract class UICollectionViewDataSource : Foundation.NSObject, IDisposable, UIKit.IUICollectionViewDataSource
[Foundation.Model]
[Foundation.Protocol]
[Foundation.Register("Microsoft_tvOS__UIKit_UICollectionViewDataSource", false)]
public abstract class UICollectionViewDataSource : Foundation.NSObject, IDisposable, UIKit.IUICollectionViewDataSource
[<Foundation.Model>]
[<Foundation.Protocol>]
[<Foundation.Register("Microsoft_iOS__UIKit_UICollectionViewDataSource", false)>]
type UICollectionViewDataSource = class
inherit NSObject
interface IUICollectionViewDataSource
interface INativeObject
interface IDisposable
[<Foundation.Model>]
[<Foundation.Protocol>]
[<Foundation.Register("Microsoft_MacCatalyst__UIKit_UICollectionViewDataSource", false)>]
type UICollectionViewDataSource = class
inherit NSObject
interface IUICollectionViewDataSource
interface INativeObject
interface IDisposable
[<Foundation.Model>]
[<Foundation.Protocol>]
[<Foundation.Register("Microsoft_tvOS__UIKit_UICollectionViewDataSource", false)>]
type UICollectionViewDataSource = class
inherit NSObject
interface IUICollectionViewDataSource
interface INativeObject
interface IDisposable
- 継承
- 属性
- 実装
注釈
UITableViewやMKMapViewなど、iOS の他の部分と同様に、UICollectionViewは、UICollectionViewDataSource クラスを介して MonoTouch で公開されているデータ ソースからデータを取得します。 このクラスは、次のようなコンテンツを UICollectionView に提供する役割を担います。
- セル – GetCell(UICollectionView, NSIndexPath) メソッドから返されます。:
- 補助ビュー – GetViewForSupplementaryElement(UICollectionView, NSString, NSIndexPath) メソッドから返されます。
- セクションの数 – NumberOfSections(UICollectionView) メソッドから返されます。 実装されていない場合、既定値は 1 です。:
- セクションあたりの項目数 – GetItemsCount(UICollectionView, IntPtr) メソッドから返されます。
UICollectionViewは再利用キューを維持し、必要以上に割り当てや割り当てを解除することなく、UICollectionReusableViewを効率的に再利用します。 GetCell(UICollectionView, NSIndexPath)とGetViewForSupplementaryElement(UICollectionView, NSString, NSIndexPath)は、コンポーネント ビューの値UICollectionReusableView変更する関数です。 これらのメソッドはスクロール中に頻繁に呼び出される可能性があるため (特に GetCell(UICollectionView, NSIndexPath))、アプリケーション開発者は不要な計算を避ける必要があります。
「コレクション ビューの概要」から取得した次のコードは、単純な UICollectionViewDataSource 実装を示しています。 モデル データを表す 3 つのセクションと大きな animal 配列があります。 セクションあたりの項目数は、 animals 配列の合計サイズの 1/3 です。
AnimalCell型はUICollectionViewCellのサブタイプであり、UIImageImage プロパティを持つものとして定義されます。GetCell(UICollectionView, NSIndexPath) メソッドは、必要に応じて、animals データから再利用されるanimalCellでこのプロパティを設定します。 同様に、UICollectionViewDataSourceは、プロジェクトで定義されているHeader型のText プロパティを設定します。
protected const int SectionCount = 3;
public override int NumberOfSections (UICollectionView collectionView)
{
return SectionCount;
}
public override int GetItemsCount (UICollectionView collectionView, int section)
{
return animals.Count / SectionCount;
}
public override UICollectionViewCell GetCell (UICollectionView collectionView, Foundation.NSIndexPath indexPath)
{
var animalCell = (AnimalCell)collectionView.DequeueReusableCell (animalCellId, indexPath);
var animal = animals [indexPath.Section * (animals.Count / SectionCount) + indexPath.Row];
animalCell.Image = animal.Image;
return animalCell;
}
public override UICollectionReusableView GetViewForSupplementaryElement (UICollectionView collectionView, NSString elementKind, NSIndexPath indexPath)
{
var headerView = (Header)collectionView.DequeueReusableSupplementaryView (elementKind, headerId, indexPath);
headerView.Text = "Supplementary View Section " + indexPath.Section.ToString ();
return headerView;
}
UICollectionViewSourceは、UICollectionViewDataSource API と UICollectionViewDelegate API を 1 つの便利なクラスに結合します。 DataSourceプロパティとDelegate プロパティに割り当てる 2 つのクラスを作成するのではなく、1 つのUICollectionViewSourceを作成してSource プロパティに割り当てることができます。
コンストラクター
| 名前 | 説明 |
|---|---|
| UICollectionViewDataSource() |
既定値を使用して新しい UICollectionViewDataSource を作成します。 |
| UICollectionViewDataSource(NativeHandle) |
アンマネージ オブジェクトのマネージド表現を作成するときに使用されるコンストラクター。 ランタイムによって呼び出されます。 |
| UICollectionViewDataSource(NSObjectFlag) |
初期化をスキップし、単にオブジェクトを割り当てるために派生クラスを呼び出すコンストラクター。 |
プロパティ
| 名前 | 説明 |
|---|---|
| AccessibilityAttributedUserInputLabels |
UICollectionViewのデータ ソース。 (継承元 NSObject) |
| AccessibilityRespondsToUserInteraction |
UICollectionViewのデータ ソース。 (継承元 NSObject) |
| AccessibilityTextualContext |
UICollectionViewのデータ ソース。 (継承元 NSObject) |
| AccessibilityUserInputLabels |
UICollectionViewのデータ ソース。 (継承元 NSObject) |
| Class |
UICollectionViewのデータ ソース。 (継承元 NSObject) |
| ClassHandle |
このクラスの Objective-C クラス ハンドル。 (継承元 NSObject) |
| DebugDescription |
UICollectionViewのデータ ソース。 (継承元 NSObject) |
| Description |
UICollectionViewのデータ ソース。 (継承元 NSObject) |
| Handle |
アンマネージ オブジェクト表現へのハンドル (ポインター)。 (継承元 NSObject) |
| IsDirectBinding |
このインスタンスが直接 Objective-C バインドを使用するかどうかを示す値を取得または設定します。 (継承元 NSObject) |
| IsProxy |
UICollectionViewのデータ ソース。 (継承元 NSObject) |
| RetainCount |
UICollectionViewのデータ ソース。 (継承元 NSObject) |
| Self |
UICollectionViewのデータ ソース。 (継承元 NSObject) |
| Superclass |
UICollectionViewのデータ ソース。 (継承元 NSObject) |
| SuperHandle |
この NSObjectの基底クラスのメソッドを表すために使用されるハンドル。 (継承元 NSObject) |
| Zone |
UICollectionViewのデータ ソース。 (継承元 NSObject) |