我最近将我的代码转换为Swift 3.0。现在,我的集合视图和表格视图数据源方法中,方法签名包含IndexPath
而不是NSIndexPath
。但是,在方法定义内部仍然需要将IndexPath强制类型转换为NSIndexPath。即,
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
let cell : NNAmenitiesOrFurnishingCollectionViewCell = self.amenitiesOrFurnishingCollectionView.dequeueReusableCell(withReuseIdentifier: "NNAmenitiesOrFurnishingCollectionViewCell", for: indexPath) as! NNAmenitiesOrFurnishingCollectionViewCell
cell.facilityImageName = self.facilityArray[(indexPath as NSIndexPath).row].imageName
cell.facilityLabelString = self.facilityArray[(indexPath as NSIndexPath).row].labelText
return cell
}
有人能告诉我为什么要将 indexPath
强制转换为 NSIndexPath
类型吗?