Swift 跳转storyboard界面黑屏解决办法

本文介绍在Swift中使用Storyboard进行界面跳转时遇到的黑屏问题及解决方法。当使用present方法跳转到新的ViewController时,若不正确设置StoryboardID,可能会导致黑屏现象。文章提供了一个有效解决方案,通过正确设置StoryboardID并调整present调用方式,可以避免此问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Swift 跳转storyboard界面黑屏解决办法

在通过storyboard创建viewController后,使用present来跳转界面:

let setPassVc = findPassViewController()
                self.present(setPassVc, animated: true, completion: {
                    print("跳转啦")
                })

会发现出现黑屏的情况
(如果此处写completion:nil 会无法跳转,出现断点)

此时应在图中
设置storyboard ID
之后通过以下语句调用

let controller = self.storyboard?.instantiateViewController(withIdentifier: String(describing: type(of: findPassViewController())))
                    as! findPassViewController
                self.present(controller, animated: true, completion: {
                    print("present")
                })
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值