title: Xamarin/MonoTouch UITableView cache
body: <p>I have a UITableView which I'm filling with images and labels.  In my source class I create  a UILabel for each cell:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
      {
          UITableViewCell cell = tableView.DequeueReusableCell (cellIdentifier);
  
          //if there are no cells create a new one
          if (cell == null)
              cell = new UITableViewCell (UITableViewCellStyle.Default, cellIdentifier);
          cell.UserInteractionEnabled = false;
  
          //create a new cellobject - this grabs the image and returns a CGBitmapContext
          CellObject _cellObject = new CellObject();
          cell.ImageView.Image = _cellObject.DrawCell(treasures[indexPath.Row].cellImage);
  
          //add text
          UILabel secondViewLabel = new UILabel();
          secondViewLabel.Text = treasures[indexPath.Row].cellTitle;
          Console.WriteLine("The title is: " + treasures[indexPath.Row].cellTitle); 
          secondViewLabel.TextColor = UIColor.White;
          secondViewLabel.TextAlignment = UITextAlignment.Center;
          secondViewLabel.Lines = 0;
          secondViewLabel.LineBreakMode = UILineBreakMode.WordWrap;
          secondViewLabel.Font = UIFont.FromName("Helvetica", 16);
          secondViewLabel.BackgroundColor = UIColor.FromRGB(205, 54, 51);
  
          //get the width of the text
          SizeF labelSize = secondViewLabel.StringSize(secondViewLabel.Text, secondViewLabel.Font);
  
          secondViewLabel.Frame = new RectangleF(0, 110 - (labelSize.Height + 10), labelSize.Width + 20, labelSize.Height + 10);
  
          //add a second view
          UIView secondView = new UIView();
          secondView.AddSubview(secondViewLabel);
          cell.ContentView.AddSubview(secondView);
  
  
          return cell;
      }
  </code></pre>
  
  <p>Which builds the table perfectly, however it seems that each cell is getting the UILabel for every other cell as well as it's own.  I can see this on shorter labels, you can see the other labels behind.  I'm loading and parsing the XML to a list, and working off that list:</p>
  
  <pre class="lang-cs prettyprint-override"><code>List&lt;Treasure&gt; treasures = new List&lt;Treasure&gt;();
  
      protected class Treasure {
          public string cellTitle { get; set; }
          public string cellTag { get; set; }
          public string cellImage { get; set; }
          public string audioFile { get; set; }
          public string mainTitle { get; set; }
          public string mainTag { get; set; }
          public string mainBody { get; set; }
          public string mainImage { get; set; }
          public string mainCaption { get; set; }
      }
  
      public CellSource (/*string[] items*/)
      {
          Console.WriteLine("CellSource called");
          string fileName = "treasuresiPhone.xml";
          XDocument doc = XDocument.Load(fileName);
          treasures = doc.Descendants("treasures").FirstOrDefault().Descendants("treasure").Select(p=&gt; new Treasure() {
              cellTitle = p.Element("celltitle").Value,
              cellTag = p.Element("celltagline").Value,
              cellImage = p.Element("cellimage").Value
          }).ToList();
  
          numCells = treasures.Count();
  
      }
  </code></pre>
  
  <p>Any ideas or advice would be appreciated.</p>
  
  <p>Thanks.</p>