我已升级到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");
};
}
答案 0 :(得分:0)
原来有一个视图正在失去它的实例。我将此视图移动到类实例,现在它可以正常工作。