【问题标题】:Xamarin iOS Simulator Showing Black ScreenXamarin iOS 模拟器显示黑屏
【发布时间】:2016-05-03 04:12:00
【问题描述】:

我正在使用 Xamarin 运行 2015 Visual Studio。当我启动 iOS 模拟器时,它在模拟器上显示黑屏。我正在使用带有导航控制器的故事板。

  • 我已将主界面设置为我的故事板。
  • 尺寸等级 - 任意/任意
  • 我已重启模拟器,运行“重置内容和设置”

AppDelegate 代码(仅包含内容的方法。):

    public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
    {
        // create a new window instance based on the screen size
        Window = new UIWindow(UIScreen.MainScreen.Bounds);
        // If you have defined a root view controller, set it here:
        Window.RootViewController = new Controllers.RegistrationController();
        // make the window visible
        Window.MakeKeyAndVisible();
        return true;
    }

【问题讨论】:

  • 你也可以添加你的 AppDelegate 代码吗?你也可以尝试在 Appdelegate 中设置一个断点来验证它是否被调用。
  • 上面添加的代码,这就是所有的代码。
  • FinishedLaunching 被调用了吗?
  • 这种情况只发生在 vs 上吗?你试过在 Mac 上使用 xamarin studio 吗?
  • 你是说启动模拟器是app还是模拟器?

标签: ios visual-studio xamarin


【解决方案1】:

你可以试试这样的:

public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
    // create a new window instance based on the screen size
    Window = new UIWindow(UIScreen.MainScreen.Bounds);

    string storyboardName = "Main";
    UIStoryboard storyboard = UIStoryboard.FromName(storyboardName, null);
    // if it is the first viewcontroller
    UIViewController vc = storyboard.InstantiateInitialViewController(); 

    // If you have defined a root view controller, set it here:
    Window.RootViewController = vc;
    // make the window visible
    Window.MakeKeyAndVisible();
    return true;
}

如果您的故事板名为 Main.stroyboard,请尝试使用:

public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
    return true;
}

我测试了这两个选项,当您的 Storyboard 被称为 Main 时,它们都应该可以工作

【讨论】:

  • 你要把它放在 FinishedLaunching 事件中吗?
  • 导航控制器应该是初始视图控制器,对吧?我将 ViewController 设置为根控制器。我在上面添加了我的故事板的图像。
  • 您的故事板是否名为 Main.storyboard?是的,应该是
  • 是的,它叫Main.storyboard。
  • 刚刚编辑了我的帖子,您能否尝试第二个建议,这听起来可能很奇怪,但请尝试一下。
【解决方案2】:

您需要从 UINavigationController 到包含内容的 UIViewController 进行 segue。如果您没有 segue,那么您的应用将显示黑屏,因为该应用认为它没有任何内容。

如果我理解正确,您的故事板可能如下所示:Storyboard 1

您需要在两个视图控制器之间创建一个 segue,以便您的故事板看起来像这样,两个视图控制器之间的 segue-arrow:Storyboard 2

【讨论】:

  • 我有一个从导航控制器到视图控制器的序列
  • 我添加了我的故事板的图像。
  • @Adam 为什么需要在 AppDelegate FinishedLaunching 中编写代码?通常你只需在 FinishedLaunching 函数中使用“return true”,即当你的故事板被称为 Main.storyboard 时。
  • 尝试在模拟器中清理、重建和删除应用程序并再次运行应用程序。
  • 那行不通。我还在模拟器上运行了“重置内容和设置”。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-10-15
  • 2013-12-17
  • 1970-01-01
  • 1970-01-01
  • 2020-01-25
  • 2014-12-03
  • 1970-01-01
相关资源
最近更新 更多