2016-09-28 321 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; 
}