我已经升级到 MonoTouch 5。自从升级后,我新创建的按钮在我现有的项目中都不起作用。在升级之前创建并绑定到事件的所有按钮仍然可以正常工作,但是一旦我创建一个新按钮并将其绑定到一个事件,应用程序就会在模拟器中崩溃。
有趣的是,当我在升级后创建一个新项目,并像往常一样在界面生成器中创建一个按钮并像往常一样将其绑定到一个事件时,它工作正常。仅当我在升级到升级前创建的现有项目后添加新按钮时才会发生崩溃。升级后创建和绑定的按钮与升级前完全相同。
我还在升级后创建了新的测试项目,并比较了 AppDelegate 和 Main cs 文件中的代码。一切都一模一样!
有什么我可能会丢失的吗?我已经搜索了互联网并尝试了包括 Stack Overflow 在内的任何地方的解决方案,但无济于事。我真的不想将现有代码移动到新项目,因为这需要大量工作。
堆栈跟踪错误:
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
该按钮在 Interface Builder 中被链接为一个插座。按钮事件代码:
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");
};
}