用于检测TableView底部的伪代码

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

 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"); } 

任何build议,以改善这个代码或任何更好的方法来检测底部?

这是我的TableView.cs类:

 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 } }