用于检测TableView底部的伪代码 [英] Pseudocode for detecting bottom of TableView

查看:22
本文介绍了用于检测TableView底部的伪代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图检测用户何时到达 Xamarin.iOS 中的表格底部.我创建了这个伪代码是为了检测底部,但是一旦应用程序运行它就会打印它已经在表格的底部,而实际上它不是..

I am trying to detect when the user gets to the bottom of the table in Xamarin.iOS. I have created this pseudocode in order to detect the bottom, however as soon as the application runs it prints that it is already at the bottom of the table when in fact it is not..

float height = tableView.Frame.Size.Height;
float contentYoffset = tableView.ContentOffset.Y;
float distanceFromBottom = tableView.ContentSize.Height - contentYoffset;

if (distanceFromBottom < height) {
    Console.WriteLine ("Bottom of Table");

    }

任何改进此代码的建议或检测底部的更好方法?

Any suggestions to improve this code or any better methods of detecting the bottom?

这是我的 TableView.cs 类:

Here is my TableView.cs Class:

public class TableView : UITableView, ITableCellProvider<Datum>
{
    public TableView ()
    {
    }

    public TableView (IntPtr handle) : base(handle)
    {
    }

    public UITableViewCell GetCell (Datum item)
    {
        var newCell = this.DequeueReusableCell(InstagramCell.Key) 
            as InstagramCell ?? InstagramCell.Create();

        newCell.Bind (item);

        return newCell;
    }

    public float GetHeightForRow (NSIndexPath indexPath)
    {
        return 340f;
    }
}

推荐答案

这样的事情应该可行:

public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
  if (indexPath.Section + 1 == NumberOfSections(tableView) && RowsInSection(tableView, indexPath.Section) == indexPath.Row + 1) {
    // this is the last row in the last section
  }
}

这篇关于用于检测TableView底部的伪代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆