Cell Reuse: Get reference of Cell that is out of table view!!

RakeshNMRakeshNM DEMember
edited November 2016 in Xamarin.iOS

Hello All,

I have a custom cell. I am trying to display images in alternative cells upto say some 20 cell [its variable: data list has 20]. For some reasons, i dont know why it is not working. It correctly display images in alternative cells upto 8 cells. However, after that then, it doesnt work that way. Also, when I scroll back top, then non of the cells will have alternate images in them.

I know about the cell reuse concept. i.e. cell which goes out of the view will be reused. However, I donno how can I reuse that cell or take the reference of the cell which goes out of the view and apply my alternate image display logic..!!

Following is my code:

In tableview controller:

TableView.RegisterClassForCellReuse(typeof(CustomCellClass), new NSString(CitiesCellId));
// If I do not register cell then, everytime new custom cell is created. This is very inefficient coding.!!! 

In Model class:

  public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
    {
        CustomCellClass cell = (CustomCellClass)tableView.DequeueReusableCell(newTableCus.CitiesCellId);

        if (cell == null)
        {
            cell = new CustomCellClass();         // when i do not register the cell this code will execute. but new cell every time :(
         }

       int row = indexPath.Row;

       if (row % 2 != 0)
            {
                 cell.Image = some image;
    }
    else
    {
       cell.Image = " no image";
    }
}

Please help.!! I am tierd of trying!!!

Answers

  • JohnMillerJohnMiller USForum Administrator, Xamarin Team Xamurai

    I don't see the problem here yet. Could you share some more info like a screenshot or screencast of what you are seeing happen?

  • RakeshNMRakeshNM DEMember
    edited November 2016

    @JohnMiller said:
    I don't see the problem here yet. Could you share some more info like a screenshot or screencast of what you are seeing happen?

    Hi John,

    Thanks for your response. Please find the attachments.

    pictures 1 and 2 is scrolling down and observe the middle image in odd cells.

    picture 3

    is still scrolling down but odd even cells middle image cells doesnt work.

    picture 4

    is scroll back to top... you can see... all the cells which had alternate middle image earlier while scrolling down is now gone!!

    1.png 77.1K
    3.png 85.1K
    4.png 87.8K
  • ManojkumarMaliManojkumarMali USMember ✭✭✭

    Hi @RakeshNM ,

    Did you get solution for this.

Sign In or Register to comment.