15
我最近將我的代碼轉換爲Swift 3.0。我的收藏視圖和表格視圖數據源方法現在在其方法簽名中包含IndexPath
而不是NSIndexPath
。但是在方法定義裏面仍然是對NSIndexPath類型轉換IndexPath。即Swift 3.0中的NSIndexPath和IndexPath
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
。