简体   繁体   English

删除UICollectionView中的单元重用

[英]Remove cell reuse in UICollectionView

I have checked alot of the questions that answer this but I believe I have a special case. 我已经检查了很多可以回答这个问题的问题,但是我相信我有一个特殊情况。

I want to caveat this by saying that I was working on an app with a friend and he went to work for Apple. 我要说的是,我正在和一个朋友一起开发一个应用程序,而他去了苹果公司工作。 I was the designer and he was the developer. 我是设计师,他是开发商。 He was teaching me Objective-C and Swift. 他在教我Objective-C和Swift。 I am updating the app he and I worked on and trying something new with it. 我正在更新他和我合作过的应用程序,并尝试使用它的新功能。 Probably way over my head but I am learning alot by working on it and doing tutorials @ Udemy and asking questions with other developers I know. 可能超出了我的脑海,但我正在通过研究它并编写@ Udemy教程并与我认识的其他开发人员提问来学习很多东西。

So I have a cirumstance where the app is using a UICollectionView to display a collection of "items". 因此,我有点奇怪,该应用程序正在使用UICollectionView来显示“项目”的集合。 When you tap a "item" it animates to a detail view of that item and gives you more information. 当您点击“项目”时,它会动画显示该项目的详细视图,并为您提供更多信息。 Cell reuse wasn't a problem until I built out a way to swipe between the items at the detail level. 直到我建立了一种在细节级别在项目之间滑动的方法,单元重用才成为问题。 (You can tap into an item detail and then swipe between those details.) (您可以点击项目详细信息,然后在这些详细信息之间滑动。)

Here is the problem: if the cell of the item isn't on screen when a user moves to the detail view and tries to swipe to that item it won't be displayed. 这是问题所在:如果当用户移至详细视图并尝试滑动到该项目时,该项目的单元格不在屏幕上,则不会显示该项目。

- (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;

} }

I understanding the dequeueReusableCellWithReuseIdentifier should be removed, but every re-write I have tried resulted in errors. 我了解应该删除dequeueReusableCellWithReuseIdentifier,但是我尝试进行的每次重写都导致错误。

- (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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM