我有一个包含许多值的 tableView。
我想获得第一indexPath.row
当前正在显示的表的值。
我怎样才能做到这一点?
我在实现 krishnabhadra 的答案时遇到以下错误:
出现错误的行是:
[self.table scrollToRowAtIndexPath:indexVis atScrollPosition:UITableViewScrollPositionTop animated:YES];
ERROR:
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.'
可能出什么问题了?
您可以使用表视图indexPathsForVisibleRows函数,它返回一个NSArray
of NSIndexPath
对于所有可见的UITableViewCell
. From indexPath.row
你可以找到你的数组索引。
NSArray *visible = [tableView indexPathsForVisibleRows];
NSIndexPath *indexpath = (NSIndexPath*)[visible objectAtIndex:0];
indexPath.row
将为您提供显示的第一个对象的索引。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)