UITableView 返回的当前行是 NSIndexPath 怎么移动到下一行呢?
1。 直接调用没有这样的函数,所以只能获取当前indexPath的 indeces,这个就是IndexPath的本质数据。这里indeces是使用的 C array方式存放的 (文档是这么写的)
NSUInteger* indeces = (NSUInteger*) malloc([currentIndexPath length] * sizeof(NSUInteger));
memset(indeces, 0, [currentIndexPath length] * sizeof(NSUInteger));
[currentIndexPath getIndexes:indeces];
indeces[1] = ((currentIndexPath.row + 1) == rowCount ? currentIndexPath.row : currentIndexPath.row + 1);
NSIndexPath* nextIndexPath = [[NSIndexPath alloc] initWithIndexes:indeces length:[currentIndexPath length]];
[nextIndexPath release];
free(indeces);
indeces = NULL;
另外 还有两种比较简单点的方法。
二
[NSIndexPath indexPathForRow:(currentIndexPath.row + 1) inSection:>currentIndexPath.section]
用这个直接创建出 indexPath。 但是 这样按照object-c编程中的建议, iphone中最好不要使用 autorelease的分配。