【问题标题】:How can i go .xib ViewController to storyboard ViewController and again storyboard to .xib ViewController我如何将 .xib ViewController 转到情节提要 ViewController,然后再将情节提要转到 .xib ViewController
【发布时间】:2020-06-02 15:05:29
【问题描述】:

这是我的第一个 .xib ViewController 我怎样才能将这个 ViewController 转到情节提要 ViewController

class FirstViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()




}

这里是故事板 secondViewController,我想再次将此 ViewController 转到 .xib ViewController

class SecondViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()




}

【问题讨论】:

  • 无法理解您要在这里做什么。

标签: ios swift


【解决方案1】:

从 .xib 到 .storyboard:

let sb = UIStoryboard(name: "the-name-of-the-storyboard", bundle: nil)
let ctrl = sb.instantiateViewController(withIdentifier: "SecondViewControllerIdentifier")
self.present(ctrl, animated: true, completion: nil)

请记住,SecondViewControllerIdentifier 是情节提要场景的标识符;它不是你的控制器的类名

从 .storyboard 到 .xib:

let ctrl = FirstViewController()
self.present(ctrl, animated: true, completion: nil)

假设存在FirstViewController.xibFirst.xib

【讨论】:

  • 我已经尝试但没有工作它显示致命错误:Unexpectedly found nil while unwrapping an Optional value,你能帮帮我吗?
  • 但是它在哪里崩溃?请调试。
  • 2020-02-18 21:01:55.858108+0600 pensacolabeach-dev[23632:424723] [客户端] 远程对象代理返回错误:错误域 = NSCocoaErrorDomain 代码 = 4099 “连接到名为com.apple.commcenter.coretelephony.xpc 已失效。” UserInfo={NSDebugDescription=与名为 com.apple.commcenter.coretelephony.xpc 的服务的连接已失效。}
  • 这似乎是您的视图控制器 的问题,并且似乎与最初的问题无关。可能与此有关:stackoverflow.com/questions/52455652/…
  • 谢谢我现在用这个正在工作 let sb = UIStoryboard(name: "the-name-of-the-storyboard", bundle: nil) let ctrl = sb.instantiateViewController(withIdentifier: "SecondViewControllerIdentifier" ) self.present(ctrl, 动画: true, 完成: nil)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-05-23
  • 2012-02-13
  • 1970-01-01
  • 2020-10-02
  • 1970-01-01
  • 1970-01-01
  • 2017-04-06
相关资源
最近更新 更多