Git Product home page Git Product logo

Comments (2)

bjhomer avatar bjhomer commented on September 23, 2024

One concern with this idea is that HSImageSidebarView reuses cells, much like UITableView does. As such, if you were to scroll a cell off the screen, its model would now be referencing a cell being used in an entirely different location. I don't think making cells retain model objects directly is a good idea for that reason. Can you think of a way this would work when the cells are being reused?

I considered allowing users to provide a UIView instead of a UIImage, but it was precisely these kinds of concerns that led me to take the image route.

I agree, though, that it's annoying to have to reload the whole sidebar just to update one image. It would make a lot of sense to add a -reloadRowAtIndex: API.

from hsimagesidebarview.

lightandshadow68 avatar lightandshadow68 commented on September 23, 2024

I use this idiom often with table views. The cell is reassigned a new model object when it is reused in the data source method.

For example...

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{    
    CellSubclass *cell = [tableView dequeueReusableCellWithIdentifier:kCellSubclassIdentifier];

    if (cell == nil)
        cell = [[[CellSubclass alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease]

    cell.model = (ModelClass*) [self.fetchedResultsController objectAtIndexPath:indexPath];

    return cell;
}

Since the cell observes it's model object property, in addition to the individual properties on the model itself, it is notified when both the cell is assigned a new model object and when observed properties of it's current model changes as well. The same notification handler can be used to update the cell's subview as appropriate in either case.

This way, much of the cell specific logic is moved to the cell subclass. Regardless of how many properties the cell and model have or how the cell's image is generated, the cellForRowAtIndexPath method remains a single property assignment.

from hsimagesidebarview.

Related Issues (6)

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.