错误信息:
ARC 不允许将“int”转换为“NSIndexPath *”
代码:
NSInteger CurrentIndex;
[self tableView:(UITableView *)horizontalTableView1 didSelectRowAtIndexPath:(NSIndexPath *)int_CurrentIndex];
如何修复此错误?
错误信息:
ARC 不允许将“int”转换为“NSIndexPath *”
代码:
NSInteger CurrentIndex;
[self tableView:(UITableView *)horizontalTableView1 didSelectRowAtIndexPath:(NSIndexPath *)int_CurrentIndex];
如何修复此错误?
您不能将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)
Swift 3.0
let indexPath : IndexPath = IndexPath(item: currentIndex, section: 0)