在iphone应用程序中。
我正在尝试让indexPath.row值在以编程方式创建的tableview中选择的行的基础上执行一些操作。
有人能告诉我为什么indexPath.row的值不正确吗?大概是21487……3?
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);谢谢,阿良
发布于 2009-08-14 23:10:28
NSIndexPath的行和节都是数组,因此从0开始,而不是从1开始。因此,NSIndexPath中的行数(或节数)实际上比最后一行的索引大1。
试一试
NSInteger lastSection = nSections - 1;
NSInteger lastRow = nRows - 1;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:lastRow inSection:lastSection];https://stackoverflow.com/questions/1280573
复制相似问题