After refreshing, some data in TableView remains old

Discussion in 'iPhone/iPad Programming' started by veliborsantic74, Sep 14, 2012.

  1. macrumors newbie

    Joined:
    Sep 6, 2012
    #1
    -------------------------------------
    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.
     
  2. macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #2
    You obviously have a bug. How do you expect anybody to help you with out posted code for the area of interest?
     
  3. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #3
    Most likely your cellForRowAtIndexPath: doesn't set all the properties correctly. Show the code.
     
  4. macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #4
    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)
    
     
  5. thread starter macrumors newbie

    Joined:
    Sep 6, 2012
    #5
    Thanks, it is done now. You really helped me to understand how it works.
     

Share This Page