c# - 简单的 Segue 在 Xamarin 中不起作用

标签 c# ios xamarin xamarin.ios xamarin-studio

我正在使用 xamarin studio 在我的应用程序中尝试一个简单的 segue。我使用 Storyboard使用“模态呈现”功能启动转场,但每次单击按钮在模拟器中执行转场时,我都会收到以下错误:

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 文件的屏幕截图。

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 类中,确保您具有以下构造函数,以便它可以从 Storyboard 中扩展:

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
}

关于c# - 简单的 Segue 在 Xamarin 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43260746/

相关文章:

ios - 归档项目 : ld: can't open output file for writing 时出错

c# - 在 Activity 中通过 Id 获取 Fragment

azure - 与 Azure Cosmos DB 离线同步

c# - 在 ASP.NET LoginName 控件中显示全名

ios - iOS8/iOS8苹果系统键盘的高度是多少?

c# - 如何从 Xamarin Forms 自定义渲染器中的 View 访问方法?

ios - 如何将 content_available 添加到 Firebase Notification Composer

c# - 应用关闭 Xamarin Forms 后丢失数据/文件

c# - 实体通用分页

c# - DevExpress GridControl 图像列显示像 System.Byte[] 这样的图像