PDA

View Full Version : After refreshing, some data in TableView remains old




veliborsantic74
Sep 14, 2012, 01:28 PM
-------------------------------------
img1 img2 img3
lbl1 lbl2 lb3 Cell 1
lbl4 lbl5 lbl6
-------------------------------------
img1 img2 img3
lbl1 lbl2 lb3 Cell 2
lbl4 lbl5 lbl6
-------------------------------------
img1 img2 img3
lbl1 lbl2 lb3 Cell 3
lbl4 lbl5 lbl6
-------------------------------------
img1 img3
lbl1 lb3 Cell 4
lbl4 lbl6
-------------------------------------
img1 img2 img3
lbl1 lbl2 lb3 Cell 5
lbl4 lbl5 lbl6
-------------------------------------
and so onů These subviews are added on cell.content. The problem is after refreshing, but only on cells on which was all subviews.
For example, after refresh cells have to looks like:
-------------------------------------
img1 img2 img3
lbl1 lbl2 lb3 Cell 1
lbl4 lbl5 lbl6
-------------------------------------
img1 img2 img3
lbl1 lbl2 lb3 Cell 2
lbl4 lbl5 lbl6
-------------------------------------
img1 img2 img3
lbl1 lbl2 lb3 Cell 3
lbl4 lbl5 lbl6
-------------------------------------
img1 img2 img3
lbl1 lbl2 lb3 Cell 4
lbl4 lbl5 lbl6
-------------------------------------
img1 img3
lbl1 lb3 Cell 5
lbl4 lbl6
-------------------------------------

but they looks like:
-------------------------------------
img1 img2 img3
lbl1 lbl2 lb3 Cell 1
lbl4 lbl5 lbl6
-------------------------------------
img1 img2 img3
lbl1 lbl2 lb3 Cell 2
lbl4 lbl5 lbl6
-------------------------------------
img1 img2 img3
lbl1 lbl2 lb3 Cell 3
lbl4 lbl5 lbl6
-------------------------------------
img1 img2 img3
lbl1 lbl2 lb3 Cell 4
lbl4 lbl5 lbl6
-------------------------------------
img1 img2 img3
lbl1 lbl2 lb3 Cell 5
lbl4 lbl5 lbl6
-------------------------------------
The middle elements in Cell 5 remains old. I am clueless how to nil them. I tried removed them from superview, set them hidden, and some other methods, but with no luck.



xStep
Sep 14, 2012, 11:56 PM
You obviously have a bug. How do you expect anybody to help you with out posted code for the area of interest?

PhoneyDeveloper
Sep 15, 2012, 12:44 AM
Most likely your cellForRowAtIndexPath: doesn't set all the properties correctly. Show the code.

Duncan C
Sep 15, 2012, 07:31 AM
-------------------------------------

--snip--

The middle elements in Cell 5 remains old. I am clueless how to nil them. I tried removed them from superview, set them hidden, and some other methods, but with no luck.

The problem is almost certainly in your cellForRowAtINdexPath method.

The basic rule is this:

First, you try to recycle a cell. If you get one, you skip the code that creates your cell, and fall into the code that FULLY configures your cells.

The code that creates a cell should add all the views to your cell, and mark the extra views with tags.

The code that configures a cell should set a value for every view, including views that you want to be empty. Set image views that are empty to a nil image, and set labels that are empty to contain an empty string. Do that by using the viewWithTag method to find the views that were added in the cell creation logic. Pseudocode:

cellForRowAtINdexPath

cell = dequeue
if (!cell)
{
add view 1 with tag 1
add view 2 with tag 2
add view 3 with tag 3
}

view1 = [cell.content viewWithTag: 1]
view1.text = content for this index path (or empty if none)

view1 = [cell.content viewWithTag: 2]
view2.image = content for this index path (or empty if none)


view3 = [cell.content viewWithTag: 3]
view3.text = content for this index path (or empty if none)

veliborsantic74
Sep 19, 2012, 02:34 PM
The problem is almost certainly in your cellForRowAtINdexPath method.

The basic rule is this:

First, you try to recycle a cell. If you get one, you skip the code that creates your cell, and fall into the code that FULLY configures your cells.

The code that creates a cell should add all the views to your cell, and mark the extra views with tags.

The code that configures a cell should set a value for every view, including views that you want to be empty. Set image views that are empty to a nil image, and set labels that are empty to contain an empty string. Do that by using the viewWithTag method to find the views that were added in the cell creation logic. Pseudocode:

cellForRowAtINdexPath

cell = dequeue
if (!cell)
{
add view 1 with tag 1
add view 2 with tag 2
add view 3 with tag 3
}

view1 = [cell.content viewWithTag: 1]
view1.text = content for this index path (or empty if none)

view1 = [cell.content viewWithTag: 2]
view2.image = content for this index path (or empty if none)


view3 = [cell.content viewWithTag: 3]
view3.text = content for this index path (or empty if none)


Thanks, it is done now. You really helped me to understand how it works.