[英]How can I use swift Viewcontroller through write coding to open the objective-c Viewcontrollerv page?
The error log like below错误日志如下
2021-06-03 09:59:16.251029+0800 testing2[7167:2095191] [Storyboard] Unknown class _TtC8testing218NextViewController in Interface Builder file. Could not cast value of type 'UIViewController' (0x1d8c46428) to 'NextViewController' (0x102a90c50). 2021-06-03 09:59:16.252513+0800 testing2[7167:2095191] Could not cast value of type 'UIViewController' (0x1d8c46428) to 'NextViewController' (0x102a90c50). (lldb)
There is a link for my demo detail https://drive.google.com/file/d/1LcY3hb3yGYf_3bZpo6qnvZPMviVp2Jft/view?usp=sharing我的演示详细信息https://drive.google.com/file/d/1LcY3hb3yGYf_3bZpo6qnvZPMviVp2Jft/view?usp=sharing有一个链接
I am a noob, please detail to say the step~ Thank you我是菜鸟,请详细说一下步骤~谢谢
Solution 1解决方案 1
You can't use pushViewController
without navigationController
.你不能在没有
navigationController
的情况下使用pushViewController
。
If you want you code will work, you need add navigationController
to you ViewController
.如果您希望您的代码能够正常工作,您需要将
navigationController
添加到您的ViewController
中。
Click to your ViewController
-> in upper menu select Editor
-> choose Embed In
-> Navigation Controller
.单击您的
ViewController
-> 在上部菜单中 select Editor
-> 选择Embed In
-> Navigation Controller
。
Solution 2解决方案 2
Add Show
segue to your NextViewController
.将
Show
segue 添加到您的NextViewController
。
Then rename to nextSegue
and change kind to Present Modally
and set presentation to Full Screen
.然后重命名为
nextSegue
并将 kind 更改为Present Modally
并将演示设置为Full Screen
。
In your ViewController
:在您的
ViewController
中:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func btn_next(_ sender: UIButton) {
performSegue(withIdentifier: "nextSegue", sender: nil)
}
}
Swift class name has module name as prefix, Make sure your ViewController
and NextViewController
both tick Inherit Module From Target with same module name in storyboard, giving the NextViewController
a identifier call next
, and you can do the following code. Swift class 名称以模块名称为前缀,确保您的
ViewController
和NextViewController
都勾选 Inherit Module From Target with same module name in storyboard,给NextViewController
一个标识符,然后您可以调用next
一个标识符。
@IBAction func btn_next(_ sender: UIButton) {
guard let next = self.storyboard?.instantiateViewController(identifier: "next") as? NextViewController else {
print("next is uninitialized")
return
}
self.present(next, animated: true, completion: nil)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.