呈现ViewController只是显示黑屏

发布于 2025-01-20 18:03:32 字数 398 浏览 2 评论 0原文

我正在尝试通过按钮操作介绍一个ViewController。但这似乎无法正常工作。我没有任何错误,但是在单击按钮后,屏幕变黑了,什么也不会发生。我唯一能找到的东西是针对Objective-C,我只是想学习Swift。我正在使用故事板来设计它,并在设计器代码中适当的位置添加了ViewController

@IBAction func doShow(_ sender: Any)
{
   var newWindowViewController = NewWindowViewController()
   newWindowViewController.baseItem = self.baseItem
   present(newWindowViewController, animated: false)
}

I am trying to present a ViewController from a Button action. But this seems to not work as i want it to. I do not get any error but after clicking the button the screen turns black and nothing happens. The only things i could manage to find are for objective-c and i am just trying to learn Swift. I am using storyboard to design this and added the Viewcontroller in the appropriate place in the designer

Code:

@IBAction func doShow(_ sender: Any)
{
   var newWindowViewController = NewWindowViewController()
   newWindowViewController.baseItem = self.baseItem
   present(newWindowViewController, animated: false)
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

真心难拥有 2025-01-27 18:03:32

您需要先从故事板上实例化视图控制器。否则,它将不会包含任何视图并将黑色变。

@IBAction func doShow(_ sender: Any)
{
    // Instantiate your ViewController here
   var newWindowViewController = storyboard?.instantiateViewController(withIdentifier: "putyourIdentifierhere")) as! NewWindowViewController
   newWindowViewController.baseItem = self.baseItem
   present(newWindowViewController, animated: false)
}

You need to instantiate the ViewController first from your storyboard. Else it won´t contain any View and turn up black.

@IBAction func doShow(_ sender: Any)
{
    // Instantiate your ViewController here
   var newWindowViewController = storyboard?.instantiateViewController(withIdentifier: "putyourIdentifierhere")) as! NewWindowViewController
   newWindowViewController.baseItem = self.baseItem
   present(newWindowViewController, animated: false)
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文