Gần đây, tôi đã chuyển đổi mã của mình sang Swift 3.0. Phương pháp nguồn dữ liệu chế độ xem và chế độ xem bảng của tôi hiện có chứa IndexPath
thay vì NSIndexPath
trong chữ ký phương thức của chúng. Nhưng vẫn bên trong định nghĩa phương thức, nó là kiểu đúc IndexPath thành NSIndexPath. tức làNSIndexPath và IndexPath trong Swift 3.0
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
}
Bất cứ ai có thể cho tôi biết lý do tại sao indexPath
được nhập vào NSIndexPath
.