【问题标题】:swift3: How to Present xib to viewcontrollerswift3:如何将 xib 呈现给 viewcontroller
【发布时间】:2017-01-06 05:15:20
【问题描述】:

我在另一个 xib 类上添加了 xib 作为子视图,并且无法从 xib 呈现到视图控制器(故事板控制器)。 我试过关注

1.

let screen:Screen32ViewController = Screen32ViewController()
self.view.window?.rootViewController?.present(screen!, animated: true,  completion: nil)

2.

let screen = self.storyboard?.instantiateViewController(withIdentifier: "Screen32ViewController") as? Screen32ViewController
self.present(screen!, animated: true,  completion: nil)

3.

let screen:Screen32ViewController = Screen32ViewController()
self.present(screen!, animated: true,  completion: nil)

这些都不适合我

提前致谢

【问题讨论】:

  • 您的根视图控制器中是否嵌入了导航控制器?
  • 是的,我有根视图控制器(导航控制器)。
  • 问题解决了 let screen = UIStoryboard(name: "storyboard name", bundle: nil).instantiateViewController(withIdentifier: "Screen32ViewController") as? Screen32ViewController self.view.window?.rootViewController?.present(screen!, animated: true, completion: nil)

标签: ios swift3 presentviewcontroller


【解决方案1】:

这样试试

let screen = UIStoryboard(name: "storyboard name", bundle: nil).instantiateViewController(withIdentifier: "Screen32ViewController") as?   Screen32ViewController
self.present(screen!, animated: true,  completion: nil)

【讨论】:

  • 它工作正常,但我在日志中出现错误“不鼓励在分离的视图控制器上显示视图控制器”
  • 出现在 self.navigationcontroller
  • 我是通过 self.window.rootviewcontroller.present 做到的,它在没有警告的情况下工作得很好。但无法使用相同的代码推送
  • 让 screen = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Screen32ViewController") as? Screen32ViewController self.navigationController?.pushViewController(screen!, animated: true)
  • 通过使用导航控制器,您可以推送该控制器
猜你喜欢
  • 2018-03-08
  • 2018-05-23
  • 1970-01-01
  • 2020-06-02
  • 1970-01-01
  • 1970-01-01
  • 2018-03-07
  • 1970-01-01
  • 2023-03-21
相关资源
最近更新 更多