![](/img/trans.png)
[英]How to navigate from swift UI to storyboard on button click in swift UI?
[英]how to call xib file from storyboard on button click in swift
我是 swift 的新手,我想在单击按钮时从故事板调用 .xib 文件。 我正在使用这样的代码,但它崩溃了,因为 .xib 文件不在故事板中
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let newViewController = storyBoard.instantiateViewController(withIdentifier: "abcViewController") as! abcViewController
self.present(newViewController, animated: true, completion: nil)
这段代码
let newViewController = abcViewController(nibName: "abcViewController", bundle: nil)
self.present(newViewController, animated: true, completion: nil)
我只是换线,现在它工作正常
let newViewController = abcViewController(nibName: "abcViewController", bundle: nil)
//self.present(newViewController, animated: true, completion: nil)
self.navigationController?.pushViewController(newViewController, animated: true)
let newViewController = abcViewController(nibName: "xibFileName", bundle: nil)
//If you want to present xib
self.present(newViewController, animated: true, completion: nil)
//If you want to push xib in navigation stack
self.navigationController?.pushViewController(newViewController, animated: true)
可以试试这个:
// Register Xib
let abcViewController = ABCViewController(nibName: "abcViewController", bundle: nil)
// Present VC "Modally" style
self.present(abcViewController, animated: true, completion: nil)
将 ID 设置为abcViewController
作为相同的类名
谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.