如何获取当前显示的tableView的indexPath.row? [英] How to get indexPath.row of tableView which is currently being displayed?

查看:2594
本文介绍了如何获取当前显示的tableView的indexPath.row?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个tableView有很多值。

I have a tableView with many values.

我想获取当前显示的表的第一个 indexPath.row 值。

I want to get the first indexPath.row value of the table which is being displayed currently.

如何实现?

在实现krishnabhadra的回答时出现以下错误:

I get Following Error while implementing krishnabhadra's answer:

错误发生的行是:

[self.table scrollToRowAtIndexPath:indexVis atScrollPosition:UITableViewScrollPositionTop animated:YES];

错误:

Assertion failure in -[NSIndexPath row], /SourceCache/UIKit_Sim/UIKit-1447.6.4/UITableViewSupport.m:2018
2011-04-01 11:57:25.458 GlossaryPro[1525:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid index path for use with UITableView.  Index paths passed to table view must contain exactly two indices specifying the section and row.  Please use the category on NSIndexPath in UITableView.h if possible.'

p>

推荐答案

您可以使用tableView indexPathsForVisibleRows 函数,它返回 NSArray UITableViewCell NSIndexPath indexPath.row 可以找到您的数组索引。

You can use tableView indexPathsForVisibleRows function, which returns an NSArray of NSIndexPath for all visible UITableViewCell. From indexPath.row you can find your array index.

NSArray *visible       = [tableView indexPathsForVisibleRows];
NSIndexPath *indexpath = (NSIndexPath*)[visible objectAtIndex:0];

indexPath.row 第一个对象显示。

这篇关于如何获取当前显示的tableView的indexPath.row?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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