Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

veliborsantic74

macrumors newbie
Original poster
Sep 6, 2012
9
0
-------------------------------------
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.
 
-------------------------------------

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

Code:
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)
 
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:

Code:
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.