Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cells seemed to be cached #24

Closed
mmarszal opened this issue Mar 1, 2013 · 19 comments
Closed

Cells seemed to be cached #24

mmarszal opened this issue Mar 1, 2013 · 19 comments
Assignees

Comments

@mmarszal
Copy link

mmarszal commented Mar 1, 2013

Hi there,

I've been using TDBadgedCell now for a while, and it seems like the cells are being cached.

When the method cellForRowAtIndexPath gets called, after getting a cell from the reuse queue, I immediately do a [cell setBadgeString:nil];
This works great, and the badge gets turned off. However, if I have more than 1 cell, after getting the requested cell, the other cells seem to use some cached value. This only happens after selecting the cell.

The code to setup the cell is as follows:

TDBadgedCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell)
    cell = [[TDBadgedCell alloc] initWithStyle:UITableViewCellStyleValue1     reuseIdentifier:CellIdentifier];

[cell setBadgeString:nil];
[[cell textLabel] setBackgroundColor:[UIColor clearColor]];
[[cell textLabel] setTextColor:[UIColor whiteColor]];
[[cell textLabel] setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:14]];
[[cell textLabel] setShadowColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:.14]];
[[cell textLabel] setShadowOffset:CGSizeMake(1.0, 1.0)];

So the flow of how i see the caching goes like this.
Create 3 cells with badges all set initially to nil.
I receive data, from 3 sources, then I set the badges to 3 different values.
Upon touching a cell, i set the badge to nil. I do this to each and every 3 cells.
Then I receive data from only one source. I then set the badge count to this value.
Upon setting the value, the other 2 cells now seem to have their data set, but form completely old value. Here is where i seem to get the cached data.

I'm really not sure how to debug this either. I set a debug point on cellForRowAtIndexPath to see if the other cells were being updated, but only the cell that was tapped gets updated by cellForRowAtIndexPath.

I've done some googling on this, and it seems some other users have ran into a similar problem. One example is here:
http://stackoverflow.com/questions/2215075/caching-issues-with-tdbadgedcell
However, this comes from 2010, and Im not sure if this issue was noticed before and fixed.

Can anyone shed any light on this? Is the information i posted above enough? Or do you need more?

Thank you

@tmdvs tmdvs closed this as completed Mar 1, 2013
@tmdvs tmdvs reopened this Mar 1, 2013
@ghost ghost assigned tmdvs Mar 1, 2013
@tmdvs
Copy link
Owner

tmdvs commented Mar 1, 2013

I've never encountered caching before as this is the first time someone's posted the bug on GitHub. I'll try get this fixed and a patch/reason why it's happening tomorrow.

Thanks for filing the bug report!

@IamAliSufyan
Copy link

i am also facing this problem. please help!

@codingarmadillo
Copy link

I seem to have the same issue. Old badges appear when I reloadrowsatindexpaths on another cell.

@tmdvs
Copy link
Owner

tmdvs commented Mar 13, 2013

I can't for the life of me recreate this. Can someone supply an example project replicating the issue?

@Andrewtait this is interesting as cells won't redraw unless told to by the table view.

@tmdvs tmdvs closed this as completed Mar 13, 2013
@tmdvs tmdvs reopened this Mar 13, 2013
@mmarszal
Copy link
Author

hi tmdvs. I'll try to come up with a demo project. unfortunately I just cant give you my active project code as the badges are updated by messages coming through sockets. I'll reply back once I get a usable demo project that reproduces the error.

@mmarszal
Copy link
Author

Okay, I came up with an example that shows this problem.
Here are the instructions on how to see it.

The sample app simply has a timer that loops every 5 seconds. On each loop, one cells badge is updated.
First let the program run until all cells have a badge.
Then click on all the cells within the 5 seconds so that all cells have their badges cleared.
Upon the next timer callback, the next cell badge will be updated, but then you will see the old cells will have cached values. If you push the entire table view up to force a redraw, you can see the proper values (ie no cached values).

My app follows a similar approach to filling the badges in. Upon row selection, the badge string is set to nil, and then once data from a socket comes in, the badge is set to the appropriate number. Hope this helps.

http://faultycode.com/badgecaching/BadgeCaching.zip

@mitchkramez
Copy link

I'm seeing this same issue. I've got some static cells that update badge counts on the fly - unfortunately, the updates only appear when you select the row, instead of updating as they're told.

self.cell1.badgeString = @"2"; //doesn't update the badge until the row is selected. if i run this call on a timer or from some other event, the badge doesn't ever update until you select the row.

@tmdvs
Copy link
Owner

tmdvs commented Mar 22, 2013

That problem isn't caching. The badge actually doesn't redraw once the cell is drawn. You could tell the badge to redraw with setNeedsDisplay however I will patch this to be automatic tonight.

Sent from my iPhone

On 22 Mar 2013, at 03:58 PM, Mitch Kramer notifications@github.com wrote:

I'm seeing this same issue. I've got some static cells that update badge counts on the fly - unfortunately, the updates only appear when you select the row, instead of updating as they're told.

self.cell1.badgeString = @"2"; //doesn't update the badge until the row is selected. if i run this call on a timer or from some other event, the badge doesn't ever update until you select the row.


Reply to this email directly or view it on GitHub.

@tmdvs
Copy link
Owner

tmdvs commented Mar 22, 2013

@mmarszal @mitchkramez @Andrewtait @AzkaarAli I'm going to do a fairly extensive rewrite of the class tonight to hopefully solve everyones problems. Its great that many others have contributed fixes but I think the time has come just to tidy the code up a little.

I'll notify you all when I push a fix tonight.

@mitchkramez
Copy link

@tmdvs calling

[self.cell1.badge setNeedsDisplay];
or
[self.cell1 setNeedsDisplay];

doesn't seem to have any effect on the badge appearing. it still doesn't appear until i've selected the row. thanks all the same, this class is very interesting and a learning experience for me. i appreciate the responses, time, and code you've put into this very much.

@mmarszal
Copy link
Author

@tmdvs I tried fixing this problem myself in the past as well, however, when it comes to core graphics, layers and animations, I'm not too useful. I only have a basic idea when it comes to layers and such (next thing on my to-learn list). But as @mitchkramez said, we appreciate the effort you've done with this class. I couldn't have my nice UI without it!

@tmdvs
Copy link
Owner

tmdvs commented Mar 22, 2013

@mitchkramez I've just pushed to the repo a fix for your issue. Simply changing the badge string should now auto redraw it!

@tmdvs
Copy link
Owner

tmdvs commented Mar 22, 2013

@mmarszal @mitchkramez @Andrewtait @AzkaarAli I've now fixed this caching bug! Check out the latest version!

@tmdvs tmdvs closed this as completed Mar 22, 2013
@mitchkramez
Copy link

Awesome - this is working as I'd expect it to now... incredible!

@codingarmadillo
Copy link

Great work, Tim. I had to do a custom cell as I was under a deadline, but will return to this in my next app. Thanks.

@mmarszal
Copy link
Author

works extremely perfectly now! Thanks for your hard work @tmdvs, it's quite appreciated.

@sberrevoets
Copy link

Just wanted to thank you for your efforts @tmdvs, I was experiencing the same problem replacing my outdated files with the latest version fixed the problem. Thanks!

@starecho
Copy link

starecho commented Oct 1, 2013

I still meet the same problem with the newest code.

@tmdvs
Copy link
Owner

tmdvs commented Oct 2, 2013

@starecho Can you provide an example where this is happening?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants