あなたが使用することができます
this._tableView.RegisterClassForCellReuse(typeof(MyCell), new NSString("MyReuseIdentifier"));
次に、を使用してセルをデキューできます
this._tableView.DequeueReusableCell("MyReuseIdentifier");
セルは自動的にインスタンス化されます。を使用してクラスを登録する必要があり[Register("MyCell")
、次のようなコンストラクターが必要です
public MyCell(IntPtr handle) : base(handle) {
}
ただし、ストーリーボードで定義したセルを再利用できるとは思いません。別の TableView インスタンスで同じセルを再利用したい場合は、セルに一意の Nib を作成すると、次のようなことがうまくいきます。
public partial class MyCell : UITableViewCell {
private MySuperCellView _mySuperNibView;
public MyCell (IntPtr handle) : base (handle) {
}
private void checkState() {
// Check if this is the first time the cell is instantiated
if (this._mySuperNibView == null) {
// It is, so create its view
NSArray array = NSBundle.MainBundle.LoadNib("NibFileName", this, null);
this._mySuperNibView = (MySuperCellView)Runtime.GetNSObject(array.ValueAt(0));
this._mySuperNibView.Frame = this.Bounds;
this._mySuperNibView.LayoutSubviews();
this.AddSubview(this._mySuperNibView);
}
}
public object cellData {
get { return this._mySuperNibView.cellData; }
set {
this.checkState();
this._mySuperNibView.cellData = value;
}
}
}
ここでは、外部 Nib で定義された一般的なビューを使用しています。まだインスタンス化されていない場合は、セルにデータを供給するときに手動でインスタンス化します。これは通常、Cell が初めてインスタンス化されたときに発生します。