0

我正在尝试让我的主屏幕正常工作,但在尝试调试时出现以下错误:

Cannot convert 'projectI.HomeScreen' expression to type '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 (homeScreen, 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 的指南时它工作得很好。

非常感谢任何帮助或领导。

4

1 回答 1

1

我也在 Xamarin 论坛上四处询问,他们建议我重试删除 ViewController 并重新制作它,因为可能原因是它没有创建 .h 文件。

之后,我使用模拟器启动了调试器,现在它可以工作了。

原因是我在 Xcode 中打开 .xib 文件时它没有创建 .h 文件。

解决方案在这里给了我

对于遇到此问题的其他任何人,我希望这对您也有帮助。

于 2013-07-29T15:09:26.430 回答