我刚刚将Monotouch升级到6,现在我的应用程序无法启动。之前它一直正常工作。现在它在Main.cs文件中抛出异常(如下所示)。我已经查看了Xamarin上的故障排除提示,但未解决问题。我已经重新布置了nib文件,移除并重新配置了我的outlets,并创建了一个全新的nib文件,看看是否可以解决问题。还有其他人有什么想法吗?
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
LoginView.designer.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;
}
}
从 Main.cs 中的代码(导致代码出现问题的地方):
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;