3

ユーザーがリストの最後に到達して新しいデータが読み込まれるとき、または取得するデータがなくなったときUITableViewを示すフッター ビューを に追加したいと考えています。UIProgresIndicatorUILabel

以下のコードを使用しましたが、何も起こりません。

UITableViewHeaderFooterView footer = new UITableViewHeaderFooterView ();

UILabel futerlabel = new UILabel ();
futerlabel.Text = "Duke u ngarkuar";

footer.AddSubview (futerlabel);

これを達成する方法。

4

3 に答える 3

3

あなたがUITableViewControllerこれを試しているなら:

        TableView.TableFooterView = footer;

アップデート

これについて考えた後、フッターを使用するのではなく、データの最後に余分なセルを使用することをお勧めします。これにより、この効果が得られます。

このメソッドを使用して、最後の項目までスクロールしたかどうかを確認し、テーブルのデータを更新します。

public override void WillDisplay (UITableView tableView, UITableViewCell cell, NSIndexPath indexPath)
    {
        // if showing last row of last section, load more
        if (indexPath.Section == tableView.NumberOfSections()-1 && indexPath.Row == tableView.DataSource.RowsInSection(tableView, indexPath.Section)-1 && !FullyLoaded) {
            var growRowSource = tableView.DataSource as GrowRowTableDataSource;
            if (growRowSource != null) {
                FullyLoaded = growRowSource.LoadNextPage ();
                Task.Delay (5000);
                tableView.ReloadData ();    
            }

        }
    }

そして、デリゲートで最後の項目をチェックし、次のように別のセルを作成します。

public override UITableViewCell GetCell (UITableView tableView, Foundation.NSIndexPath indexPath)
    {
        if (indexPath.Row == LoadedItems.Count) {
            var loadingCell = tableView.DequeueReusableCell (LoadingCellID, indexPath) as LoadFooterCell;
            loadingCell.Loading = !hasNextPage;
            return loadingCell;
        }
        var cell = tableView.DequeueReusableCell (CellID, indexPath) as GrowRowTableCell;
        var item = LoadedItems [indexPath.Row];

        // Setup
        cell.Image = UIImage.FromFile(item.ImageName);
        cell.Title = item.Title;
        cell.Description = item.Description;

        return cell;
    }
    bool hasNextPage;

ここで、GrowTable Xamarin サンプル コードの例を簡単にモックしました: https://github.com/b099l3/LoadingTableExample

于 2016-04-22T15:37:36.803 に答える