我正在开发一个使用MvvmCross的应用程序,该应用程序使用UI的故事板。而不是像我的表格单元格那样使用XIB文件,例如Stuart的小猫示例,在故事板中创建单元格。一切正常,细胞正在创建,但出于某种原因我得到了
MvxBind:Warning: 11.57 Failed to create target binding for binding Text for Title
错误。单元格原型上有三个标签,一个图像和一个按钮,但我现在只对标签进行绑定(标题,描述和日期)。应用程序工作正常,但单元格显示为空,我甚至添加了一些复选标记,它们显示确定。进一步挖掘后,我发现我的标签是空的,如果我从代码中添加一个新标签,它就可以正常显示
这是代码:
TableViewController
partial class CreateView : MvxTableViewController
{
public CreateView (IntPtr handle) : base (handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
var source = new MvxSimpleTableViewSource(TableView, typeof(CreateTableCellView), CreateTableCellView.Key);
TableView.Source = source;
var set = this.CreateBindingSet<CreateView, CreateViewModel>();
set.Bind(source).For(s => s.ItemsSource).To(vm => vm.CreatedItems);
set.Apply();
TableView.ReloadData();
}
}
TableViewCell
partial class CreateTableCellView : MvxTableViewCell
{
public static readonly NSString Key = new NSString("CreateCell");
private UILabel _label;
public CreateTableCellView(IntPtr handle)
: base(handle)
{
//_imageViewLoader = new MvxImageViewLoader(() => this.imgThumb);
_label = new UILabel(new RectangleF(0, 0, 320, 44));
_label.BackgroundColor = UIColor.Blue;
_label.TextColor = UIColor.White;
Add(_label);
this.DelayBind(() =>
{
var set = this.CreateBindingSet<CreateTableCellView, CreateModel>();
// the label added in code works fine
set.Bind(_label).To(vm => vm.Title);
// the lables below are null
set.Bind(lblTitle).To(vm => vm.Title);
set.Bind(lblDescripton).To(vm => vm.Descripton);
set.Bind(lblDate).To(vm => vm.Date);
//set.Bind(_imageViewLoader).To(vm => vm.ThumbImage);
set.Apply();
});
}
}
TableViewCell设计器
[Register ("CreateTableCellView")]
partial class CreateTableCellView
{
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UIButton btnDelete { get; set; }
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UIImageView imgThumb { get; set; }
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UILabel lblDate { get; set; }
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UILabel lblDescripton { get; set; }
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UILabel lblTitle { get; set; }
void ReleaseDesignerOutlets ()
{
if (btnDelete != null) {
btnDelete.Dispose ();
btnDelete = null;
}
if (imgThumb != null) {
imgThumb.Dispose ();
imgThumb = null;
}
if (lblDate != null) {
lblDate.Dispose ();
lblDate = null;
}
if (lblDescripton != null) {
lblDescripton.Dispose ();
lblDescripton = null;
}
if (lblTitle != null) {
lblTitle.Dispose ();
lblTitle = null;
}
}
}
关于为什么原型单元格中的元素为空的任何想法?我使用了设计师在sotryboard上的所有其他控制器和你的工作完美,唯一的null是在TableViewCell的类。