2016-09-28 316 views
0

我已經檢查了很多答案,但我相信我有一個特例。刪除UICollectionView中的單元格重用

我想告訴你這一點,我說我正在和一個朋友一起開發一個應用程序,然後他去爲Apple工作。我是設計師,他是開發人員。他教我Objective-C和Swift。我正在更新他和我一起工作的應用程序,並嘗試使用新的應用程序。可能是我頭上的方法,但我正在學習很多東西,並且在Udemy上做了一些教程,並向我認識的其他開發人員提問。

因此,我有一個應用程序使用UICollectionView來顯示「項目」集合的情況。當你點擊一個「物品」時,它會動畫到該物品的詳細視圖,併爲您提供更多信息。直到我構建出在細節級別的項目之間滑動的方式之後,細胞再利用才成爲問題。 (你可以點擊一個項目的細節,然後在這些細節之間滑動。)

這是問題:如果該項目的單元格不在屏幕上,當用戶移動到詳細視圖並嘗試滑動到該項目不會顯示。

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
KNIIssueCollectionViewCell *cell = (KNIIssueCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:kItemCellReuseID forIndexPath:indexPath]; 

KNIRecommendedItem *item = self.issue.items[indexPath.item]; 
[cell configureWithItem:item]; 

KNIRecommendedItemDetailViewController *itemDetailVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:NSStringFromClass([KNIRecommendedItemDetailViewController class])]; 
itemDetailVC.item = item; 
itemDetailVC.transitioningDelegate = self; 
itemDetailVC.itemImage = cell.image; 
[self.pages addObject:itemDetailVC]; 
return cell; 

}

我理解dequeueReusableCellWithReuseIdentifier應該被刪除,但每次重寫我試圖導致錯誤。

+0

什麼是你刪除出隊後編寫的代碼 – prabodhprakash

+0

單元複用不是你的問題。無論何時您認爲禁用細胞重複使用可以解決您的問題,您可能不瞭解您的問題。單元格只是模型中某些數據的視圖。即使您想要在詳細信息視圖中顯示的項目當前未顯示在集合視圖中,該項目仍然存在於您的數據模型中,並且這是您需要從中獲取的項目。你沒有「特殊情況」。 – Paulw11

+0

謝謝@ Paulw11 - 這有點清除了我對它的一些想法。但是你把它比我頭腦中的簡潔得多。也許我正在處理錯誤位置的問題... – UEXUI

回答

0
- (UICollectionViewCell *)collectionView:(UICollectionView 
*)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    KNIIssueCollectionViewCell *cell = //create new cell instance here 

    KNIRecommendedItem *item = self.issue.items[indexPath.item]; 
    [cell configureWithItem:item]; 

    // ...other part of code... // 
    return cell; 
}