[英]Swift 2.0 error Downcast from '[NSIndexPath]?' to '[indexpath]' only unwraps optional
[英]Can you downcast a NSIndexPath to NSInterger
我在详细视图中使用的AVPlayer类采用了Int类型的indexPath。
我从表视图tableViewDidSelectAtIndexPath获取indexPath,然后将其发送到详细信息VC以使用。
我试图只是简单地将NSIndexPath转换为! NSInteger在将其发送给详细VC之前可以使用,但是它崩溃时没有崩溃消息。 因此,我对如何执行此操作有些困惑。
有可能对此cast之以鼻吗? 如何将NSIndexPath中的数字获取到Int中以便可以在班级中使用它?
NSIndexPath
始终*是节和行 (对于UITableView
)或项 (对于UICollectionView
)的组合。
您需要通过访问单个索引来分解该部分:
id object = [[self dataSource] objectAtIndex:[indexPath row]];
*编辑
分别评论:您是对的。 NSIndexPath
可以使用多个索引。
如果您知道有多个索引(在UITableViewDelegate
是我所不希望的),则可以迭代索引:
for (int i = 0; i < [indexPath length]; i++) {
NSUInteger index = [indexPath indexAtPosition:i];
// use index to access whatever you want
}
编辑
在下次询问之前, 请阅读文档和标题。 小提示: cmd- 单击 NSIndexPath
将带您进入带有所有可能信息的头文件。
目标C
NSInteger currentRow = indexPath.row;
迅速
let currentRow = self.tableView.indexPathForSelectedRow().row
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.