在UITableview部分中获取最后一个单元格 [英] Get last cell in a UITableview section

查看:690
本文介绍了在UITableview部分中获取最后一个单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UITableView中有一个有多行的部分。我希望获得该部分的最后一行或最后一个单元格,以便在其上添加披露指标。

I have a section in UITableView which has multiple rows. I wish to get the last row or the last cell of the section to add a disclosure indicator on it.

我想要使用的一种方式是:

One way I am thinking to use is:

NSIndexPath *lastCellIndexPath = [NSIndexPath indexPathForItem:[self.tableView numberOfRowsInSection:2]-1 inSection:2];

是否还有其他最佳方法可以获取某个部分上最后一个单元格的单元格或索引路径?

Is there any other best way to get the cell or indexpath of the last cell on a section?

推荐答案

    NSInteger totalRow = [tableView numberOfRowsInSection:indexPath.section];//first get total rows in that section by current indexPath.
    if(indexPath.row == totalRow -1){
         //this is the last row in section.
    }

希望有所帮助。

我在 tableView中执行了此操作:willDisplayCell:forRowAtIndexPath:方法

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

这篇关于在UITableview部分中获取最后一个单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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