我是 swift 的新手,我想在单击按钮时从 Storyboard 中调用 .xib 文件。 我正在使用这样的代码,但它崩溃了,因为 .xib 文件不在 Storyboard中
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)
关于ios - 如何在快速单击按钮时从 Storyboard 中调用 xib 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59152183/