動的に変化するテーブルの最後にボタンを追加することに興味があります。ボタンをクリックするとテーブルにセルが追加されますが、テーブルの下部がスクロールされたときにのみボタンが表示されるようにしたいと思います。この問題を解決する方法について何かアイデアがあるかどうかを知りたいです。
1 に答える
2
で作っUIViewて入れたらどうですか?UIButtonFooterView
tableView.TableFooterView = MyView;
UITableViewCell他の解決策は、データ セルの後にボタンを追加することです。これは、によって行われるべきUITableViewSourceです。最後のセルを含むすべてのロジックを、最後のセルの機能を処理する抽象クラスに移動すると便利です。
(name it ) の独自の抽象サブクラスを作成します。これには以下が含まれます。UITableViewSourceUITableViewSourceWithFooter
UITableViewCellボタン付き;- パラメーターに対して可視である必要が
bool IsLastCellIndexPath(NSIndexPath ip)ある場合に true を返すMethod 。コード:last cellNSIndexPath
protected bool IsLastCellIndexPath(NSIndexPath ip)
{
return ip.Row == GetRecordsCount();
}
- 抽象メソッド
GetRecordsCount(), RowsInSection方法。Sealedサブクラスでのオーバーライドを避けるため。GetRecordsCount()代わりにメソッドを実装します。
public sealed override int RowsInSection (UITableView tableview, int section)
{
return GetRecordsCount() + 1;
}
次に、のサブクラスを実装して使用しますUITableViewSourceWithFooter。
- いくつ
GetCellかのロジックを作成します。
if (base.IsLastCellIndexPath(indexPath) {
return base.cell_with_button;
} else {
return data_cell;
}
- メソッド
GetRecordsCount()。簡単に言うと、次のようになります。
List<item_class> items;
...
protected override GetRecordsCount()
{
return items.Count;
}
于 2013-06-21T09:28:07.363 に答える