views:

26

answers:

2

I am making app where a list of countries to be shown. when the first time app runs the user selects the no. of countries..i stored that list in nsuser defaults..i want to checkmark those countries in the tableview when the app runs again for second time...

one more problem is when i scroll through the table view..and again comes to the previous position..the checkmark does not show...why this happens??

A: 

This happens because the table Cells are reused so when you Scroll up they are cleaned and reused by the below data and when you go up again all the thing is happened again.

Regarding Checking again on second time. Just store the index of the row in NSUserDefault and put the condition in cellForRowAtIndexPath that when the index is matched keep it Checked.

Hope this helps..

hAPPY cODING...

Suriya
This is bad advice. Do reuse cells, we want smooth scrolling after all.
Johan Kool
I know Johan dats why I have answered his question below that line only. I know dat reusable cell is d only thing advisable but We must know how to break all things. So my cellidentifier line was just for knowledge not for implementation. Still coz of downvote I have removed it finally. Thanks for suggestion
Suriya
+1  A: 

In -tableView:cellForRowAtIndexPath: you should set wether or not a checkmark should be shown based on your internal model (which in your case comes from NSUserDefaults). In the tableView:didSelectRowAtIndexPath:, do not simply make the checkmark visible in the cell, but store in in your internal model as well. This way when a cell is being shown again, it will show up correctly.

Johan Kool