Coder Social home page Coder Social logo

Comments (3)

mwyman avatar mwyman commented on June 9, 2024

The point of the datasource method is to recycle the cell views. You're only setting the image at the time you first create the cell, so I'd completely expect that when you scroll far enough to recycle cells, they'll show the old images.

Your code should be more like:

GMGridViewCell *cell = [gridView dequeueReusableCell];
if ( !cell ) {
    cell = [[GMGridViewCell alloc] init];

    cell.contentView = [[UIImageView alloc] init];
}

NSString *imageName = [NSString stringWithFormat:@"%@.png", [_data objectAtIndex:index]];
[(UIImageView *)cell.contentView setImage:[UIImage imageNamed:imageName]]

return cell;

Also, the [[cell.contentView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)] probably isn't needed (and wasn't doing anything in your example, as it has no subviews of cell.contentView), and not wanted, since you should reset the contents of your cell views, not recreate them every time...

from gmgridview.

gmoledina avatar gmoledina commented on June 9, 2024

Thanks for your explanation @mwyman !

from gmgridview.

acecapades avatar acecapades commented on June 9, 2024

Hello,

I'm also using GMGridView which is fantastic for supporting grid views. But I'm encountering problems regarding the way it dequeues cells.

Some background info on my app: I have a class named 'ProductsGVC' which presents a grid view of products belonging to a certain 'Category'. ProductsGVC's data model is an array of products taken from an instance of a 'Category'.

My GMGridView creates 250 cells at a time. As I load each cell, I have a thread that downloads an image for each cell. While waiting for it to finish downloading, I put a default image in the cell's image view. Logically, after downloading the cell, I want to reload the cell to update the photo. I'm successful at doing this using this code:

//_currentData is my array of products
[_gmGridView reloadObjectAtIndex:[_currentData indexOfObject:product] animated:YES];

However, if the a cell that is in the bottom part of my array is updated, the cell is refreshed properly but 1 cell disappears.

My inefficient solution is to call [_gmGridView reloadData] anytime a cell finishes downloading its image. The result is, the cells I've loaded before, disappear. I'm guessing their dequeued and reused. Well, they do appear again when I scroll a number of times away from those cells that disappeared.

My question is, how do I prevent dequeue-ing a visible cell (i.e. a cell that is currently on-screen)?

from gmgridview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.