Xamarin.ios 将UiTableViewCell子类用作Monotouch.Dialog元素
我正试图找出如何: 1.在Xcode 4+中使用IB可视化地创建UITableViewCell的自定义子类,以便在MT中使用Xamarin.ios 将UiTableViewCell子类用作Monotouch.Dialog元素,xamarin.ios,monotouch.dialog,Xamarin.ios,Monotouch.dialog,我正试图找出如何: 1.在Xcode 4+中使用IB可视化地创建UITableViewCell的自定义子类,以便在MT中使用 如何将该自定义类用作MT.Dialog中的元素 我进行了广泛的搜索,没有找到任何例子或能够解决它。 以下是我一直在尝试的过程: 步骤1似乎很简单,因为我找到了一个很好的教程: 第二步似乎是我被卡住的地方。一旦我有了新类,在这种情况下,在它上面有一些标签: public partial class CustomListCell : UITableViewCell { p
public partial class CustomListCell : UITableViewCell {
public CustomListCell () :base(UITableViewCellStyle.Default,"CellID") {
}
public void UpDateData(string lbl1, string lbl2, string lbl3) {
this.lblLabel1.Text = lbl1;
this.lblLabel2.Text = lbl2;
this.lblLabel3.Text = lbl3;
}
}
public partial class CustomListCell :Element
但是标签控件似乎并不是每次都被创建。无论我在哪里调用UpdateData,它们都是空的,因此是空引用异常,即使构造函数执行得很好。我也试着让它成为一个OwnerDrawneElement,但是遇到了一些问题
这可能吗?有推荐的款式吗?我想您要找的样品是OwnerDrawnCell: 查看它如何重写GetCell()方法以提供自定义单元格:
public override UITableViewCell GetCell (UITableView tv)
{
OwnerDrawnCell cell = tv.DequeueReusableCell(this.CellReuseIdentifier) as OwnerDrawnCell;
if (cell == null)
{
cell = new OwnerDrawnCell(this, this.Style, this.CellReuseIdentifier);
}
else
{
cell.Element = this;
}
cell.Update();
return cell;
}
您只需要做同样的事情-除了需要用加载XIB的单元格替换OwnerDrawnCell
我还写了一篇博客文章,介绍了如何使用DequeueReusableCell API的新iOS6变体从XIBs加载传感器-请参阅