【发布时间】:2014-03-29 23:35:06
【问题描述】:
我使用 Xamarin 创建了一个 Instagram 客户端类型的应用程序。当我最初运行应用程序时,它显示前 4 个或 5 个,当我一直向下滚动时,所有单元格都会消失并显示为空。以下是单元格的显示方式:
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 对象子类化到 TableView.cs 类下。很抱歉造成混乱:)
【问题讨论】:
-
请添加更多信息,您提供的代码示例没有提供足够的信息。可以添加GetCell方法的代码吗?
-
@choper 我已经添加了获取单元格类
-
get cell上面的方法是bind方法@choper
-
“获取单元格是绑定方法”是什么意思?根本不是标准的 GetCell 方法,如果您使用的不是标准的 UITableViewSource 似乎没有覆盖然后通知这一点,因为我现在看到的不能与 UITableViewSource 一起使用
-
@choper 我提供了完整的课程和描述。很抱歉造成混乱。
标签: ios uitableview xamarin tableview instagram