C# 无法将主屏幕表达式转换为类型MonoTouch.UIKit.UIViewController
我正在尝试使主屏幕正常工作,但在尝试调试时出现以下错误:C# 无法将主屏幕表达式转换为类型MonoTouch.UIKit.UIViewController,c#,xamarin.ios,C#,Xamarin.ios,我正在尝试使主屏幕正常工作,但在尝试调试时出现以下错误: 无法将“projectI.HomeScreen”表达式转换为类型“MonoTouch.UIKit.UIViewController”(CS1503) 我看了一张照片,但这对我不起作用。谷歌搜索也没什么帮助 我试图重新创建该项目,但在调试该项目时发生了相同的错误 “我的AppDelegate.cs”文件中出现以下错误: public partial class AppDelegate : UIApplicationDelegate {
无法将“projectI.HomeScreen”表达式转换为类型“MonoTouch.UIKit.UIViewController”(CS1503)
我看了一张照片,但这对我不起作用。谷歌搜索也没什么帮助
我试图重新创建该项目,但在调试该项目时发生了相同的错误
“我的AppDelegate.cs”文件中出现以下错误:
public partial class AppDelegate : UIApplicationDelegate
{
// class-level declarations
UIWindow window;
//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
//
// You have 17 seconds to return from this method, or iOS will terminate your application.
//
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
// create a new window instance based on the screen size
this.window = new UIWindow (UIScreen.MainScreen.Bounds);
// Create a new root view controller
UINavigationController rootNavController = new UINavigationController ();
// Set the homescreen
HomeScreen homeScreen = new HomeScreen ();
rootNavController.PushViewController (homeScreen, false);
// make the window visible
this.window.RootViewController = rootNavController;
this.window.MakeKeyAndVisible ();
return true;
}
}
错误发生在这一行:
rootNavController.PushViewController(主屏幕,false)代码>
HomeScreen.cs看起来像这样:
public partial class HomeScreen : UIViewController
{
public HomeScreen () : base ("HomeScreen", null)
{
}
public override void DidReceiveMemoryWarning ()
{
// Releases the view if it doesn't have a superview.
base.DidReceiveMemoryWarning ();
// Release any cached data, images, etc that aren't in use.
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Perform any additional setup after loading the view, typically from a nib.
}
}
我不知道它为什么要这样做,当我遵循Xamarin的指导时,它工作得非常好
非常感谢任何帮助或线索。我也在Xamarin论坛上询问过,他们建议我重试删除ViewController并重新制作,因为原因可能是它没有创建.h文件
完成后,我使用模拟器启动了调试器,现在它可以工作了
原因是当我在Xcode中打开.xib文件时,它没有创建.h文件
我得到了解决办法
对于遇到此问题的任何其他人,我希望这也能对您有所帮助。仅是主屏幕代码,还是它附带了一个XIB(Interface Builder)文件?还有一个XIB文件。该接口实际上是用XCode接口生成器创建的。