gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 11:46:52 29 4
gpt4 key购买 nike

我正在使用 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com