简体   繁体   中英

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. 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.

So I have a cirumstance where the app is using a UICollectionView to display a collection of "items". 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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