2013-02-04 88 views
1

試圖瞭解mvvmcross和廈門國際銀行的編輯 - 我按照示例代碼從mvvmcross數據綁定幫助需要

http://slodge.blogspot.co.uk/2013/01/uitableviewcell-using-xib-editor.html

並結合我的一些代碼中。

namespace ConX.UI.Touch.Cells 
{ 
[Register("JobCell")] 
    public partial class JobCell : MvxBaseBindableTableViewCell 
    { 
    public static NSString Identifier = new NSString("JobCell"); 
    public const string BindingText = @"{'JobDescription':{'Path':'Description'}, 'JobScheduledForDate':{'Path':'ScheduledForDate'}, 'JobNumber':{'Path':'JobNo'}}"; 


    public JobCell(): base(BindingText) 
    { 
    } 

    public JobCell(IntPtr handle): base(BindingText, handle) 
    { 
    }  

    public JobCell (string bindingText): base(bindingText, UITableViewCellStyle.Default, Identifier) 
    { 
    } 

    public string JobDescription 

    { 
     get { return this.DescriptionLabel.Text; } 
     set { this.DescriptionLabel.Text = value; } 
    } 


    public string JobScheduledForDate 
    { 
     get { return ScheduledForDateLabel.Text; } 
     set { ScheduledForDateLabel.Text = value; } 
    } 


    public string JobNumber 
    { 
     get { return NumberLabel.Text; } 
     set { NumberLabel.Text = value; } 
    } 

} 

}

using MonoTouch.Foundation; 

namespace ConX.UI.Touch.Cells 
{ 
partial class JobCell 
{ 
    [Outlet] 
    MonoTouch.UIKit.UILabel DescriptionLabel { get; set; } 

    [Outlet] 
    MonoTouch.UIKit.UILabel ScheduledForDateLabel { get; set; } 

    [Outlet] 
    MonoTouch.UIKit.UILabel NumberLabel { get; set; } 

    void ReleaseDesignerOutlets() 
    { 
     if (DescriptionLabel != null) { 
      DescriptionLabel.Dispose(); 
      DescriptionLabel = null; 
     } 

     if (ScheduledForDateLabel != null) { 
      ScheduledForDateLabel.Dispose(); 
      ScheduledForDateLabel = null; 
     } 

     if (NumberLabel != null) { 
      NumberLabel.Dispose(); 
      NumberLabel = null; 
     } 
    } 
} 

}

我只是不能與拋出下面的錯誤這項工作 - 似乎網點沒有被創造出來的?

System.NullReferenceException: Object reference not set to an instance of an object 
at ConX.UI.Touch.Cells.JobCell.set_JobDescription (System.String value) [0x00008] in 
/Volumes/ConXPrototype/Conx.UI.Touch/Cells/JobCell.cs:32 
at  
     ConX.UI.Touch.Views.BaseJobListView`2+TableSource[ConX.Core.ViewModels.JobListViewModel,Syst 
em.DateTime].GetOrCreateCellFor (MonoTouch.UIKit.UITableView tableView, 
MonoTouch.Foundation.NSIndexPath indexPath, System.Object item) [0x00025] in 
/Volumes/ConXPrototype/Conx.UI.Touch/Views/BaseJobListView.cs:101 
at Cirrious.MvvmCross.Binding.Touch.Views.MvxBaseBindableTableViewSource.GetCell 
(MonoTouch.UIKit.UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) 
[0x00000] in <filenam 

exception

非常感謝 克恩

回答

1

我猜你正在運行的MvvmCross框架二進制文件的舊版本。

我們在過去的4周內做出了一些關鍵性的改變,這些改變延遲了數據綁定的發生,直到細胞和來源真正可用於綁定。你可以看到這些變化在Bindable Cell changes on GitHub

有兩種可能的解決方法:

A.升級到較新的組件 - 記錄該博客文章時所使用的那些是https://github.com/slodge/MvvmCross-Tutorials/tree/master/Lib/MvvmCross(或有釋放目前雙星http://slodge.blogspot.co.uk/p/mvvmcross-binaries_7.html

B.OR保持上了年紀的組件,但你需要像測試的空控制,以保護您的get/set方法:

public string JobNumber 
{ 
    get { return NumberLabel == null ? null : NumberLabel.Text; } 
    set { if (NumberLabel == null) return; NumberLabel.Text = value; } 
} 

很抱歉在圖書館這一變化 - MvvmCross也不斷提高,樣品/博客文章並不總是趕上,這可以在樣品中引起混亂。


如果您選擇更新到最新的組件,然後瑞士綁定語法也將變得可用,允許你切換從:

public const string BindingText = @"{ 
    'JobDescription':{'Path':'Description'}, 
    'JobScheduledForDate':{'Path':'ScheduledForDate'}, 
    'JobNumber':{'Path':'JobNo'}}"; 

public const string BindingText = @" 
    JobDescription Description; 
    JobScheduledForDate ScheduledForDate; 
    JobNumber JobNo"; 

但這隻有一個選項 - 如果你願意,你可以堅持使用JSON。

更多關於瑞士的裝訂,請參見http://blog.ostebaronen.dk/2013/01/awesome-mvvmcross-swiss-bindings-for.html

+0

二進制文件已更新,切換到RegisterNibForCellReuse()客場笑。 謝謝Stuart - 真棒框架。 – Kern