20

错误信息:

ARC 不允许将“int”转换为“NSIndexPath *”

代码:

NSInteger CurrentIndex;

[self tableView:(UITableView *)horizontalTableView1 didSelectRowAtIndexPath:(NSIndexPath *)int_CurrentIndex];

如何修复此错误?

4

2 回答 2

81

您不能将int变量NSIndexPath直接转换为。但是你可以NSIndexPath从一个int变量中创建一个。

您需要一个section索引和row索引来制作NSIndexPath. 如果你UITableView只有一个section,那么:

Objective-C

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:rowIndex inSection:0];

迅速

let indexPath: NSIndexPath = NSIndexPath(forRow: rowIndex, inSection: 0)

斯威夫特 4

let indexPath = IndexPath(row: rowIndex, section: 0)
于 2012-10-21T11:46:55.637 回答
4

Swift 3.0

let indexPath : IndexPath = IndexPath(item: currentIndex, section: 0)
于 2016-09-29T06:54:20.913 回答