简单的 Segue 在 Xamarin 中不起作用

Simple Segue not working in Xamarin

我正在使用 xamarin studio 在我的应用程序中尝试一个简单的 segue。我使用故事板使用 "present modally" 函数启动 segue,但每次我单击按钮在模拟器中执行 segue 时,我都会收到以下错误:

Failed to marshal the Objective-C object 0x7f8018511770 (type: loginViewController). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'iOSApp.loginViewController' does not have a constructor that takes one IntPtr argument).

知道是什么导致了这个问题吗?我也附上了我的 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.
        }


    }
}

在您的 LoginViewController class 中,确保您具有以下构造函数,以便它可以从故事板中膨胀:

protected YourClassNameViewController(IntPtr handle) : base(handle)
{
    // Note: this .ctor should not contain any initialization logic.
}

如果您的 class 名字是 loginViewController,那么您的 class 将类似于:

protected partial class loginViewController : UIViewController
{
    public loginViewController(IntPtr handle) : base (handle)
    {
       // Note: this .ctor should not contain any initialization logic.
    }

    ~~~~ rest of class
}