简体   繁体   English

UITableView最后一个单元格

[英]UITableView Last cell

我怎么知道何时显示UITableView的最后一个单元格,何时数据来自数据库并且我不知道确切的单元格数量。

If you know your number of cells in the table and you wish to just know when the last row will appear, you could implement: 如果你知道表格中的单元格数量,并且想知道最后一行何时出现,你可以实现:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

and compare the row with your table rowcount. 并将该行与您的表rowcount进行比较。 This method it being triggered just before a row to be shown. 这个方法是在一行显示之前触发的。

-(NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section 

此函数从ur表视图返回单元格的no

The proper way to handle a table view is to define a number of sections and a number of rows in each section for your table view in the table view controller. 处理表视图的正确方法是在表视图控制器中为表视图的每个部分定义多个部分和多个行。 If you don't know the length of the table, you're already in trouble. 如果您不知道桌子的长度,那么您已经遇到了麻烦。

A common way to handle this is to load your data from the database into an array and then use the length of the array as the table length. 处理此问题的常用方法是将数据从数据库加载到数组中,然后使用数组的长度作为表长度。 Once you have that, the UITableViewController class should have some sort of method for getting the index path of the last cell. 一旦你有了,UITableViewController类应该有一些方法来获取最后一个单元格的索引路径。 Once you have that you call '[indexPath row]' and you're golden. 一旦你有了,你称之为'[indexPath row]',你就是金色的。 Read up on UITableViews it's a complex subject if you go into depth. 阅读UITableViews如果你深入了解它是一个复杂的主题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM