ios - 如何在快速单击按钮时从 Storyboard 中调用 xib 文件

标签 ios swift storyboard xib

我是 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)

画面是这样的 enter image description here

我只是换了行,现在它工作正常

 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/

相关文章:

ios - 当从调度队列中的服务器检索数据时,如何处理应用程序进入后台?

Swift Firebase 读取一个 child 的 child

点击后退按钮时,iOS 8 屏幕滑动方向错误

ios - 将项目从 XIB/NIB 移动到 Storyboard

objective-c - 一对多关系中的 KVO 对象属性

objective-c - 如何在 map View 上添加透明蒙版

iphone - 如何在 swift 中验证 iOS 应用程序

iOS Split View Controller ,以编程方式更改多个 Storyboard的 View

ios - UITableView 在每个部分返回相同的项目

ios - NSSearchPathForDirectoriesInDomains 的应用程序 ID 更改每个模拟器在真实设备上运行和更新应用程序