I am trying to create a custom cell that just simply displays an image in a listview. I don't need labels but the guides seem to indicate that custom cells have labels (I don't know if this is true). I'm subcassing UITableViewCell as shown here:
using System;
using Foundation;
using UIKit;
namespace Talli.iOS
{
public class CollageImageListViewCelliOS : UITableViewCell
{
private NSString cellIdentifier;
private int row;
UIImageView imageView;
UILabel headingLabel, subheadingLabel;
public CollageImageListViewCelliOS(NSString cellIdentifier, int row)
{
SelectionStyle = UITableViewCellSelectionStyle.Default;
this.cellIdentifier = cellIdentifier;
this.row = row;
BackgroundView = new UIImageView { Image = ToImage(this.row) };
headingLabel = new UILabel();
subheadingLabel = new UILabel();
}
internal UIImage ToImage(int rowItem)
{
UserPost p = new UserPost();
p.SetUserPost(rowItem);
UIImage img = FromUrl(p.URL);
return img;
}
internal void UpdateCell(int rowItem)
{
UserPost p = new UserPost();
p.SetUserPost(rowItem);
imageView = new UIImageView { Image = ToImage(this.row) };
Console.Write(p.URL);
ContentView.AddSubview(imageView);
ContentView.AddSubview(headingLabel);
ContentView.AddSubview(subheadingLabel);
}
public override void LayoutSubviews()
{
base.LayoutSubviews ();
imageView.Frame = new CoreGraphics.CGRect(0,0,ContentView.Bounds.Width,80);
//headingLabel.Frame = new CoreGraphics.CGRect (5, 4, ContentView.Bounds.Width - 63, 25);
subheadingLabel.Frame = new CoreGraphics.CGRect (0, 0, 0, 0);
imageView.Frame = new CoreGraphics.CGRect (0,0,0,0);
}
static UIImage FromUrl(string uri)
{
using (var url = new NSUrl(uri))
using (var data = NSData.FromUrl(url))
return UIImage.LoadFromData(data);
}
}
}
That said, I wonder if anything is loaded from here because from my subclassed UITableViewSource code, I put in a debug breakpoint in GetCell
method and it never hits.
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
// request a recycled cell to save memory
CollageImageListViewCelliOS cell = tableView.DequeueReusableCell(cellIdentifier) as CollageImageListViewCelliOS;
// if there are no cells to reuse, create a new one
if (cell == null)
{
cell = new CollageImageListViewCelliOS(cellIdentifier, indexPath.Row);
}
cell.UpdateCell(indexPath.Row);
return cell;
}
Does anyone have any suggestions as to why I am not getting any images to show in my list?