首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >不符合键值编码(单点触控和iOS 6)

不符合键值编码(单点触控和iOS 6)
EN

Stack Overflow用户
提问于 2012-09-25 07:42:46
回答 4查看 6K关注 0票数 17

我刚刚把我的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");
    }

下面是我调用ViewController的AppDelegate中的代码片段:

        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;
EN

回答 4

Stack Overflow用户

发布于 2012-09-25 10:02:38

它会告诉你原因:[<UIApplication 0xc84bb10> setValue:forUndefinedKey:]。请注意,它并没有显示:[<LoginView 0xc84bb10> setValue:forUndefinedKey:]。现在,您需要找出是什么在尝试向UIApplication实例发送消息-setBtnNewAccount:

看起来委托在某个地方设置错了。

票数 3
EN

Stack Overflow用户

发布于 2014-04-30 16:28:41

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

我的解决方法是删除按钮,然后手动搜索并删除设计器文件中的所有引用。

希望这能帮到你。

票数 2
EN

Stack Overflow用户

发布于 2015-08-19 00:21:54

我甚至在最近的Xamarin Studio (5.9.5)的构建中也遇到了这个问题。“与Xcode同步”选项是灰色的,但很明显,我在Tamarin中的ViewController xib文件与Xcode不同步。

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12574444

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档