Image Persistence In UITableViewCell

Discussion in 'iOS Programming' started by Darkroom, Sep 13, 2009.

  1. Darkroom Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #1
    i have a table view with custom buttons for each cell. these buttons overlap one another, becoming visible/hidden depending on the app's current state. to simplify the issue, i'll stay that each of my cells have one red button and one green button. if the app is in state A, the buttons are red. state B, green.

    my tableview can is animated into and off of the main view. each time the animation occurs the tableview is reloaded. but sometimes when the app is in state A and the tableview animates back onto the screen, all of the cells with buttons that completely fit in the tableview are of the correct red color except for the last cell, which is only partially visible and mostly outside of the scroll area is green. however, the last cell's wrong color only lasts for a second, quickly switching to the correct color.

    i'm being picky. but how can i resolve this issue?
     
  2. North Bronson macrumors 6502

    Joined:
    Oct 31, 2007
    Location:
    San José
    #2
    When you say: "each time the animation occurs":

    Are you calling [customTableView reloadData] before you call the animations? After?

    Are you calling [customTableView reloadData] in the animation delegate (when the animation actually starts)?
     
  3. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #3
    ok i found a way to always reproduce the error without animation, which should help me explain it better, and hopefully find a solution.

    my tableview can show 5 cells at a time. all the cell's backgrounds are green. if i press a button all the cell's backgrounds become red. after turning the backgrounds red, scrolling up or down to the cells that were not visible during the color switch are cells that will only change when they are scrolled into view.

    the color change is an quick animation (greenbackground.alpha = 0.0, redbackground.alpha = 1.0 over 0.5 seconds) which could be the cause of the delayed transition if what i'm seeing is normal behavior for the reusing of tableview cells. however, only the first cell off tableview that is scrolled to is affected, while cells that come after have already changed to the correct color: my table view fits 5 cells on screen, a quick scroll down will reveal cell 6 and 7. when cell 6 scrolls into view it is still of the old color and quickly animates to the correct color to match all the other cells, but cell 7 has already transitioned with the rest before cell 6, even though both were off view during the switch.
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    I would suspect that this is because cell 6 is actually using a new cell whereas cell 7 is reusing a previously queued cell (probably cell 0, which is now off-screen).
     
  5. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #5
    i suspect you're right. would you agree that there's probably nothing i can do to remedy this?
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    I would agree. It seems like you are trying to do something with a table view that it really is not at all intended to do. For example, when you say "if i press a button all the cell's backgrounds become red", what is the purpose of this change? What does the change in background color signify? Perhaps there is some other, more standard way to achieve the notification to the end user of some change.
     
  7. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #7
    This is probably your bug.

    When cells are reused they still go through your cellForRowAtIndexPath. If you reuse a cell there then you shouldn't animate its change from one color to the other. Just change it.
     
  8. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #8
    i was just using the background color change as an example. in my actual app, a button appears (fades in) and disappears (fades out) for each cell, according to the current setting. so scrolling to cell 6 and 7 when the button should already be present, shows the button fade in on cell 6 instead of already being there like in all the other cells.

    it's really not that big of an issue, but since i'm a total masochist with the need to drown myself in every last detail to achieve some degree of content, having it not do this would be great. :)
     
  9. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #9
    Alright then, let me reword this: "what is the purpose of this change? What does the change in ___ signify?". The thing I'm trying to get at here is not the "what" that you're trying to achieve but the "why". Does it serve a purpose for the end user or is it there just because it perhaps looks cool?

    "Achieve some degree of content"? What do you mean by that? Based on this and other posts of yours, it seems you really are wanting to do things "outside the box". That's fine, but then you can no longer expect all the "containment" that the box provided in the first place.
     
  10. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #10
    i just noticed that my animation occurs within this method, before the cell is returned.

    i could set the duration of the animation to zero if a new cell is scrolled onto the screen after the color switch occurs, to eliminate noticeability. but figuring out how to do that might be a hackjob.
     
  11. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #11
    oh, i'm just being cynical. i agree, and don't necessarily expect the SDK to abide by my expectation.
     
  12. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #12
    They have this invention called if statements.

    Code:
    if (wantsAnimation)
    {
         // start animation here
    }
    
    // do stuff with cell
    
    if (wantsAnimation)
    {
         // end animation here
    }
    
    try it, you might like it.
     

Share This Page