2012-09-24 20 views
17

我剛剛將我的Monotouch升級到6,現在我的應用程序無法啓動。它以前工作沒有任何問題。現在它在Main.cs文件中引發一個異常(下面列出)。我已經瀏覽了Xamarin的故障排除提示,但並未解決問題。我重新佈置了筆尖文件,刪除並重新配置了我的插座,並創建了一個全新的筆尖,以查看是否可以解決問題。其他人有任何想法嗎?從LoginView.designer.cs非關鍵值編碼兼容(Monotouch和iOS 6)

MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown. Name: NSUnknownKeyException Reason: [<UIApplication 0xc84bb10> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key btnNewAccount. 
    at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr) 
    at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38 
    at Pokr.Application.Main (System.String[] args) [0x00000] in /Users/James/Projects/App/Main.cs:17 

代碼:從Main.cs

[Register ("LoginView")] 
partial class LoginView 
{ 
    [Outlet] 
    MonoTouch.UIKit.UIImageView imgLogo { get; set; } 

    [Outlet] 
    MonoTouch.UIKit.UITextField txtEmail { get; set; } 

    [Outlet] 
    MonoTouch.UIKit.UITextField txtPassword { get; set; } 

    [Outlet] 
    MonoTouch.UIKit.UIButton btnLogin { get; set; } 

    [Outlet] 
    MonoTouch.UIKit.UIButton btnNewAccount { get; set; } 

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

    [Outlet] 
    MonoTouch.UIKit.UIImageView imgKeyboardBorder { get; set; } 

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

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

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

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

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

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

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

代碼(其中代碼休息):

static void Main (string[] args) 
    { 
     UIApplication.Main (args, null, "AppDelegate"); 
    } 

這裏是我的AppDelegate其中片段我打電話給ViewController:

 var rootNavigationController = new UINavigationController(); 

     LoginView loginScreen = new LoginView(); 
     rootNavigationController.PushViewController(loginScreen, false); 

     this.window.RootViewController = rootNavigationController; 

     //blank function fires so the getter will init the singleton. 
     Singleton.Instance.Initialize(); 

     // make the window visible 
     window.MakeKeyAndVisible(); 


     return true; 
+0

如果可能,還需要更多代碼。 – fuzz

+0

增加了一些代碼,它只是設計器生成的代碼。但是,它應該讓你瞭解設計師正在同步什麼。正如我所說的,它在升級之前就起作用了所以,我很好奇它是否是一個Monotouch /開發bug。 – jamesbar2

回答

18

當您在代碼中初始化了ViewController,並且還有從XIB文件初始化的ViewController時,會發生此錯誤。

如果你有「主界面」值設置爲你在代碼中創建一個ViewController這種情況可能發生。要解決此問題,請將該值清空,然後不會自動初始化ViewController

還要檢查你的PINFO文件,看看是否有一個主界面集。

由於@BartXamarin用戶提供這個提示:在Xamarin工作室(第4節)

右擊項目選擇'Options',然後根據'iOS Project'(第'iPad Deployment info')。清除下拉列表'Main Interface'並且應該解決問題。

+2

這解決了它!謝謝一堆。這是在我的應用程序設置中定義了一個主界面。 – jamesbar2

+2

謝謝!同樣在這裏:右鍵單擊Xamarin Studio中的項目(第4版)選擇'選項',然後在'iOS項目'(部分'iPad部署信息')我必須清除下拉菜單'主界面'並解決它。 – Bart

3

它告訴你原因:[<UIApplication 0xc84bb10> setValue:forUndefinedKey:]。請注意,這並不是說:[<LoginView 0xc84bb10> setValue:forUndefinedKey:]。現在您需要弄清楚什麼是試圖將消息-setBtnNewAccount:發送到UIApplication的實例。

它看起來像一個委託設置錯了地方。

+0

嗯。我不確定委託人是如何被設計人員/ mono開發人員分配錯誤的。我注意到,雖然,並且很困惑爲什麼它在應用程序的根,而不是在控制器。也許iOS 6調用函數的方式有所改變? – jamesbar2

2

我有類似的問題,從按鈕創建網點,從而消除那些和他們建立網點。某處Xcode和Xamarin之間同步並沒有以正確的方式完全做到了......

修復對我來說是刪除按鈕,然後搜索和手動刪除在設計文件中的所有引用。

希望這有助於...

1

我面對這個問題,即使在最近的構建Xamarin工作室(5.9.5)的。 「與Xcode同步」選項呈灰色,但顯然,我的ViewController在Tamarin中的xib文件與Xcode不同步。

定盤由Hutjepower提到的相同。我搜索了Xamarin Studio中的破損引用,打開Xamarin內的xib文件(右鍵單擊該文件並使用源代碼編輯器),然後刪除通過Xcode刪除的控件。這解決了這個問題。

1

我也在Xamarin Studio 5.10.1中遇到了這個問題;我最終發現,如果我使用文本編輯器來編輯故事板文件,並刪除了所有內容,但它爲我解決了這個問題。

相關問題