我正在使用xamarin studio在我的应用程序中尝试一个简单的segue。我使用故事板使用“当前模态”功能启动segue,但每次单击按钮在模拟器中执行segue时,我都会收到以下错误:
无法封送Objective-C对象0x7f8018511770(类型:loginViewController)。找不到此对象的现有托管实例,也无法创建新的托管实例(因为“iOSApp.loginViewController”类型没有带有一个IntPtr参数的构造函数。)
有什么可能导致问题的想法?我也附上了我的main.storyboard文件的截图。
以下代码段是我的ViewController.cs
文件和loginViewController.cs
代码
using System;
using UIKit;
namespace iOSApp
{
public partial class ViewController : UIViewController
{
protected ViewController(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
}
public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
// Release any cached data, images, etc that aren't in use.
}
}
}
和
using System;
using UIKit;
namespace iOSApp
{
public partial class loginViewController : UIViewController
{
public loginViewController(IntPtr handle) : base(handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
}
public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
// Release any cached data, images, etc that aren't in use.
}
}
}
答案 0 :(得分:1)
在LoginViewController
班级中,请确保您拥有以下构造函数,以便可以从故事板中对其进行充气:
protected YourClassNameViewController(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
}
如果您的班级名称为loginViewController
,那么您的班级将如下所示:
protected partial class loginViewController : UIViewController
{
public loginViewController(IntPtr handle) : base (handle)
{
// Note: this .ctor should not contain any initialization logic.
}
~~~~ rest of class
}