iOS unread cell icon

215 views Asked by At

I am trying to figure out the best way to implement the blue dot like the Mail app for unread cells. I have the blue dot but I am just trying to figure out the logic behind it. The table is populated by an xml file. Right now I have it set as so, when the parsing method is called, it sets a boolean to NO within the data object. Then when the tableview populates itself, if the boolean is NO, the image is displayed, and then during didSelectRowAtIndex, I then set the boolean to YES and the image disappears. The problem lies here, every time I refresh the table, the xml is re-parsed and the instance variable is reset to NO and the user is informed that the cell hasn't been clicked. How do I fix that? What's the best logic around it?

2

There are 2 answers

1
Michael Dautermann On

Instead of re-parsing the XML each time you refresh the table, parse it once and then save the data (or an array of dictionaries, or whatever) it parsed out into as a variable within the object.

That way, the state of the "read" blue dot or "unread" will persist between table reloads.

0
TotoroTotoro On

Michael Dautermann is making a good point in his answer. For your situation, where the feed is often refreshed, you can keep a set where you keep track of the read elements by storing their ID's there (whatever they are). Then, in your tableView:cellForRowAtIndexPath: method, you just check if the current element's id exists in the set, and don't show the "new" image if it does.