开发者

Some cell in table view should be checkmarked?

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 TableView and again come to the开发者_StackOverflow中文版 previous position, the checkmark does not show. Why this happens??


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜