简体   繁体   中英

Passing data between UICollectionViewCells

I am using a UICollectionView , in which one UICollectionViewCell covers the entire screen. Inside my UICollectionViewCell , I give people the opportunity to add text ( UILabel ), images ( UIImageView ) and color ( UIColor ). Now when the user navigates to the next cell i want the color, labels and image views to be displayed exactly as they were added on the previous cell. The users also have the option to pinch and pan the labels and images. In short, how can i pass on data from one cell to another?

I see several ways how to do this depending on your realization: use global properties/ivars to store the selected data from user input. In either case you probably handle UITextFiledDelegate methods in your controller or extract the cell by indexPath and copy values from the current cell to the next one.

And when the user presses the "Continue" button you:

1) If you create all you collectionViewCells at once in cellForItemAtIndexPath , then you should only reload the necessary cell via - (void)reloadItemsAtIndexPaths:(NSArray *)indexPaths and set the values you have saved previously.

2) If you create cells but the next one is not ready (for instance you save the memory) - all almost the same - you add a new cell to the collectionView and read the data from your properties.

3) If you have not a "Continue" button or/and user can swipe the cell in every moment - so you can reload the cell in scrollViewDidScroll (or scrollViewWillBeginDragging) or extract the existent by indexPath and modify it without reloading.

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