ios - UICollectionView loading cell data in wrong places -


I have a UICollectionView displaying the grid of a custom cell. When I set up a method on the cell subclass I cell phone in the setup cellForItemAtIndexPath to the UI phone (eg [cell setupUI] ). This method is loading some labels, but it also calls an async method that receives images from the web. I am using AFNetworking to handle it.

My point is that sometimes (images) images are loaded into the correct cells + cells in which the image should not be set. Loading data is just in random cells.

I was looking at it for a while and tried many approaches, but I do not know where I am wrong. Do I have a catch which I am missing?

NB: I have checked and the method sets these image cells, they are called the correct number (3), but the images are visible on 5 cells.

>

Edit

This is the code used to fetch images I have used this without the first CollectionView (drawing the grid itself ) And it worked fine:

  [self.youtubeThumbnail setImageWithURLRequest: request placeholderImage: zero breakthrough: ^ (NSURLRequest * request, NSHTTPURLResponse * response, UIImage * image) {weakImageView.image = image; } Failure: ^ (NSURLRequest * request, NSHTTPURL response; response, NSError * error) {}];  

Weak imageview is a weak reference to the image view of my cell. The above code is in the cell subclass and is called from cellForItemAtIndexPath.

I should say this method is run on dispatch_async (dispatch_get_global_queue) and the image load is on dispatch_async (dispatch_get_main_queue).

Solution

So my problem was really awkward. My collection view was being reloaded several times and due to this the data Was displayed several times in the wrong cells. I still do 100% not sure why this is the case, but I have hacked it all around, whether the material has been reloaded, the installation of a ball, and the reply to stop the reload It is right that I have been able to correct ASIN loading, which was also part of this issue. Thanks for your help. The text "itemprop =" text ">

after

might be related to cell reuse without providing code (though, I'm just guessing). As you are scrolling through a collection scene, the cells that are visible on the screen are recycled, and after re-using the scrolling to avoid overhead to create a ton object. There is more information in class reference.

More specifically, the problem you are seeing is that unless the response to your network is decreasing, that cell initially made a request offscreen, following the old sample app of Apple Can fix it The implementation of the key startIconDownload is: forIndexPath :. in RootViewController

  [iconDownloader setCompletionHandler: ^ {UITableViewCell * cell = [self.tableView cellForRowAtIndexPath: indexPath]; // Display new load image cell ImageView.image = appRecord.appIcon; // Remove the icon Deloder from the progress list. // Its result will be deloculated [remove Self.imageDownloadsInProgress OBjectForKey: indexPath]; }];  

So when the image is finished downloading, the table view prevents the correct cell to fit the image which sets the image view. Therefore, you will have the right table view cell or (or in your case, the collection view cell). And, if a request is closed off the cell fire but then it is scrolled before it comes down, there is nothing you need to worry about because the tableview / CollectionView method will not return to the secret cells equal to no is.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -