【问题标题】:Not Key Value Coding Compliant (Monotouch and iOS 6)不符合键值编码(Monotouch 和 iOS 6)
【发布时间】:2012-09-24 23:42:46
【问题描述】:

我刚刚将 Monotouch 升级到 6,现在我的应用无法启动。它以前可以正常工作,没有任何问题。现在它在 Main.cs 文件中引发异常(如下所列)。我查看了 Xamarin 上的故障排除提示,但没有解决问题。我重新布置了笔尖文件,删除并重新配置了我的插座,并创建了一个全新的笔尖,看看这是否能解决问题。其他人有什么想法吗?

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");
    }

这是我调用 ViewController 的 AppDelegate 中的 sn-p:

        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;

【问题讨论】:

  • 添加了一些代码,它只是设计器生成的代码。但是,它应该让您了解设计师正在同步的内容。正如我所说,它在升级之前工作。所以,我很好奇这是否是 Monotouch/develop 的错误。

标签: c# ios xamarin.ios interface-builder ios6


【解决方案1】:

当您在代码中初始化了 ViewController 并且还从 XIB 文件中初始化了 ViewController 时,会发生此错误。

如果您将“主界面”值设置为您在代码中创建的ViewController,则可能会发生这种情况。为解决此问题,将此值设为空,则不会自动初始化ViewController

同时检查您的 pInfo 文件以查看是否设置了主界面。

感谢 @BartXamarin 用户提供此提示:

在 Xamarin Studio (v.4) 中右键单击项目选择'Options',然后在'iOS Project' 下('iPad Deployment info' 部分)。清除下拉列表'Main Interface' 应该可以解决问题。

【讨论】:

  • 这修复了它!谢谢一堆。在我的应用程序设置中定义了一个主界面。
  • 谢谢!此处相同:在 Xamarin Studio (v.4) 中右键单击项目选择“选项”,然后在“iOS 项目”下(“iPad 部署信息”部分)我必须清除下拉“主界面”并解决它。
【解决方案2】:

它告诉你原因:[&lt;UIApplication 0xc84bb10&gt; setValue:forUndefinedKey:]。注意它不是说:[&lt;LoginView 0xc84bb10&gt; setValue:forUndefinedKey:]。现在您需要弄清楚是什么试图将消息 -setBtnNewAccount: 发送到 UIApplication 的实例。

看起来委托在某处设置错误。

【讨论】:

  • 嗯。我不确定委托是如何设置错误的,因为它是由设计师/单声道开发分配的。我确实注意到了这一点,并且很困惑为什么它在应用程序的根目录中而不是在控制器中。也许 iOS 6 调用函数的方式发生了一些变化?
【解决方案3】:

我在从按钮创建插座时遇到了类似的问题,因此删除这些按钮并从中创建插座。某处 XCode 和 Xamarin 之间的同步没有完全以正确的方式完成......

对我来说修复是删除按钮,然后手动搜索并删除设计器文件中的所有引用。

希望这会有所帮助...

【讨论】:

    【解决方案4】:

    即使在最近的 Xamarin Studio (5.9.5) 版本中,我也遇到了这个问题。 “与 Xcode 同步”选项显示为灰色,但显然我在 Tamarin 中的 ViewController xib 文件与 Xcode 不同步。

    修复与 Hutjepower 提到的相同。我在 Xamarin Studio 中搜索了损坏的引用,在 Xamarin 中打开了 xib 文件(右键单击该文件并使用源代码编辑器),然后删除了我通过 Xcode 删除的控件。这解决了这个问题。

    【讨论】:

      【解决方案5】:

      我在使用 Xamarin Studio 5.10.1 时也遇到过这个问题;我最终发现,如果我使用文本编辑器来编辑我的故事板文件并删除了

      <connections></connections>
      

      它为我解决了问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多