我创建了一个使用Xamarin的Instagram客户端类型应用程序。当我最初运行应用程序时,它会显示第一个4或5,当我一直向下滚动时,所有单元格消失并显示空白。下面是电池应该如何显示:TableViewCell内容正在消失
TableView.cs
public class TableView : UITableView, ITableCellProvider<Datum>
{
public TableView()
{
}
public TableView (IntPtr handle) : base(handle)
{
}
public UITableViewCell GetCell (Datum item)
{
var newCell = this.DequeueReusableCell(InstagramCell.Key)
as InstagramCell ?? InstagramCell.Create();
newCell.Bind (item);
return newCell;
}
public float GetHeightForRow (NSIndexPath indexPath)
{
return 340f;
}
}
InstagramCell.cs
public partial class InstagramCell : UITableViewCell
{
private Datum datum;
public static readonly UINib Nib = UINib.FromName ("InstagramCell", NSBundle.MainBundle);
public static readonly NSString Key = new NSString ("InstagramCell");
public InstagramCell (IntPtr handle) : base (handle)
{
}
public static InstagramCell Create()
{
return (InstagramCell)Nib.Instantiate (null, null) [0];
}
public void Bind(Datum datum)
{
this.datum = datum;
if (this.datum == null || this.datum.caption == null)
{
this.TextLabel.Text = "null";
return;
}
else
{
this.captionLabel.Text = datum.caption.text;
}
Task.Factory.StartNew (async() => {
this.pictureImage.InvokeOnMainThread (() => this.pictureImage.SetImage (
url: new NSUrl (datum.images.standard_resolution.url)
)
);
this.profileImage.InvokeOnMainThread (() => this.profileImage.SetImage (
url: new NSUrl (datum.user.profile_picture)
)
);
});
this.nameLabel.Text = this.datum.user == null ? "user is null" : datum.user.full_name;
}
}
我已经使用SimplyMobile创建单元格内容。 ITableCellProvider是SimplyMobile的子类。我也在InstagramCell.cs
中使用MonoTouch.dialog
和System.Threading.Tasks
。在我的MainViewController.xib中,我继承TableView.cs
类下的TableView对象。对不起,困惑:)
请添加更多信息,您提供的代码示例没有提供足够的信息。你可以添加GetCell方法的代码吗? – choper
@choper我已添加获取单元格类 – Prad
获取单元格上方的方法是绑定方法@choper – Prad