简体   繁体   English

升级后,Monotouch在单击按钮时崩溃

[英]Monotouch crashes on button click after upgrade

I have upgraded to MonoTouch 5. Ever since the upgrade none of my newly created buttons work in my existing projects. 我已经升级到MonoTouch5。自升级以来,新创建的按钮都无法在现有项目中使用。 All the buttons created and bound to events before the upgrade still work perfectly but as soon as I create a new button and bind it to an event, the app crashes in the simulator. 升级之前创建并绑定到事件的所有按钮仍然可以正常工作,但是一旦我创建一个新按钮并将其绑定到事件,该应用程序就会在模拟器中崩溃。

The interesting part is that when I create a new project after the upgrade, and create a button in interface builder as I usually did it and bind it to an event as I usually did, it works fine. 有趣的部分是,当我升级后创建一个新项目,并像往常一样在界面生成器中创建一个按钮并将其绑定到事件时,它可以正常工作。 The crash only happens when I add a new button after the upgrade to an existing project that was created before the upgrade. 仅当我在升级到在升级之前创建的现有项目后添加新按钮时,才会发生崩溃。 The buttons created and bound after the upgrade is done exactly the same as those done before the upgrade. 升级后创建和绑定的按钮与升级前完全相同。

I have also created new test projects after the upgrade and compared the code in the AppDelegate and Main cs files. 升级后,我还创建了新的测试项目,并比较了AppDelegate和Main cs文件中的代码。 Everything is exactly the same! 一切都一样!

Is there something I might be missing? 我可能会缺少一些东西吗? I have scouted the internet and tried solutions from everywhere including Stack Overflow but to no avail. 我搜寻了互联网并尝试了包括堆栈溢出在内的所有解决方案,但无济于事。 I do not really want to move the existing code to new projects as it is a lot of work. 我真的不想将现有代码移至新项目,因为这需要大量工作。

Stack Trace Error: 堆栈跟踪错误:

012-07-03 19:18:30.189 Calculator[605:1207] -[__NSCFType btnSave:]: unrecognized selector sent to instance 0x7106fd0

Unhandled Exception: MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: -[__NSCFType btnSave:]: unrecognized selector sent to instance 0x7106fd0
  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) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29 
  at ScamCalculator.Application.Main (System.String[] args) [0x00000] in /Users/joachimpr/Projects/ScamCalculator/ScamCalculator/Main.cs:17 
[ERROR] FATAL UNHANDLED EXCEPTION: MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: -[__NSCFType btnSave:]: unrecognized selector sent to instance 0x7106fd0
  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) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29 
  at ScamCalculator.Application.Main (System.String[] args) [0x00000] in /Users/joachimpr/Projects/ScamCalculator/ScamCalculator/Main.cs:17 

The button is linked up as an outlet in Interface Builder. 该按钮在Interface Builder中链接为插座。 The button event code: 按钮事件代码:

public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();

            // Perform any additional setup after loading the view, typically from a nib.

            btnSave.TouchUpInside += (sender, e) => {
                Console.WriteLine("click");
            };
        }

Turns out there was a view that was losing its instance. 原来有一个观点正在失去其实例。 I moved this view to a class instance and now it works fine. 我将此视图移到了一个类实例,现在可以正常工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM