微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

objective-c – 如何从int创建NSIndexPath?

错误信息:

cast of ‘int’ to “NSIndexPath *’ is disallowed with ARC

码:

NSInteger CurrentIndex;

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

如何解决这个错误

解决方法

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

您需要一个部分索引和行索引来创建一个NSIndexPath.如果你的UITableView只有一个部分,那么:

Objective-C的

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

迅速

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐