首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何获取IndexPath

如何获取IndexPath
EN

Stack Overflow用户
提问于 2009-08-14 22:52:17
回答 1查看 11.4K关注 0票数 2

在iphone应用程序中。

我正在尝试让indexPath.row值在以编程方式创建的tableview中选择的行的基础上执行一些操作。

有人能告诉我为什么indexPath.row的值不正确吗?大概是21487……3?

代码语言:javascript
复制
NSUInteger nSections = [myTableView numberOfSections];
NSUInteger nRows = [myTableView numberOfRowsInSection:nSections];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow: nRows inSection:nSections];
NSLog(@"No of sections in my table view %d",nSections); 
NSLog(@"No of rows in my table view %d",nRows);
NSLog(@"Value of selected indexPath Row %d", indexPath.row);

谢谢,阿良

EN

回答 1

Stack Overflow用户

发布于 2009-08-14 23:10:28

NSIndexPath的行和节都是数组,因此从0开始,而不是从1开始。因此,NSIndexPath中的行数(或节数)实际上比最后一行的索引大1。

试一试

代码语言:javascript
复制
NSInteger lastSection = nSections - 1;
NSInteger lastRow = nRows - 1;    
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:lastRow inSection:lastSection];
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1280573

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档