Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
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?
 

North Bronson

macrumors 6502
Oct 31, 2007
395
1
San José
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?

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)?
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
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.
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
...but cell 7 has already transitioned with the rest before cell 6, even though both were off view during the switch.
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).
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
would you agree that there's probably nothing i can do to remedy this?
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.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
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.
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
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.

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. :)
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
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.
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?

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. :)
"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.
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
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.

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.
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
"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.

oh, i'm just being cynical. i agree, and don't necessarily expect the SDK to abide by my expectation.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.