【发布时间】:2020-03-27 20:22:21
【问题描述】:
我是 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)
【问题讨论】:
-
故事板里面有 xib 吗?
-
@Sailendra 不,它不在里面。
-
如果我错了,请纠正我,你在故事板中有一个按钮,你想在按钮点击右键时加载一个 xib?
-
@Sailendra 完成了,谢谢您的宝贵时间。
标签: ios swift storyboard xib