HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 如何获取当前正在显示的tableView的indexPath.row?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个包含许多值的tableView.

我想@L_696_2@当前显示的表的第一个indexPath.row值.

我怎样才能做到这一点?

在实现krishnabhadra的答案时,我得到以下错误

出现错误的行是:

[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.'

可能有什么不对?

解决方法

您可以使用tableView indexPathsForVisibleRows函数,该函数为所有可见的UITableViewCell返回NSIndexPath的NSArray.从indexPath.row您可以找到您的数组索引.
NSArray *visible       = [tableView indexPathsForVisibleRows];
NSIndexPath *indexpath = (NSIndexPath*)[visible objectATindex:0];

indexPath.row将为您显示一个对象的索引.

大佬总结

以上是大佬教程为你收集整理的ios – 如何获取当前正在显示的tableView的indexPath.row?全部内容,希望文章能够帮你解决ios – 如何获取当前正在显示的tableView的indexPath.row?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。