<legend id='TIqmN'><style id='TIqmN'><dir id='TIqmN'><q id='TIqmN'></q></dir></style></legend>
      • <bdo id='TIqmN'></bdo><ul id='TIqmN'></ul>
      <i id='TIqmN'><tr id='TIqmN'><dt id='TIqmN'><q id='TIqmN'><span id='TIqmN'><b id='TIqmN'><form id='TIqmN'><ins id='TIqmN'></ins><ul id='TIqmN'></ul><sub id='TIqmN'></sub></form><legend id='TIqmN'></legend><bdo id='TIqmN'><pre id='TIqmN'><center id='TIqmN'></center></pre></bdo></b><th id='TIqmN'></th></span></q></dt></tr></i><div id='TIqmN'><tfoot id='TIqmN'></tfoot><dl id='TIqmN'><fieldset id='TIqmN'></fieldset></dl></div>

      1. <tfoot id='TIqmN'></tfoot>
      2. <small id='TIqmN'></small><noframes id='TIqmN'>

        从 xib 文件加载 ViewController

        Loading ViewController from xib file(从 xib 文件加载 ViewController)
        <i id='2LX4X'><tr id='2LX4X'><dt id='2LX4X'><q id='2LX4X'><span id='2LX4X'><b id='2LX4X'><form id='2LX4X'><ins id='2LX4X'></ins><ul id='2LX4X'></ul><sub id='2LX4X'></sub></form><legend id='2LX4X'></legend><bdo id='2LX4X'><pre id='2LX4X'><center id='2LX4X'></center></pre></bdo></b><th id='2LX4X'></th></span></q></dt></tr></i><div id='2LX4X'><tfoot id='2LX4X'></tfoot><dl id='2LX4X'><fieldset id='2LX4X'></fieldset></dl></div>
          <tbody id='2LX4X'></tbody>

          <small id='2LX4X'></small><noframes id='2LX4X'>

            <tfoot id='2LX4X'></tfoot>

            • <legend id='2LX4X'><style id='2LX4X'><dir id='2LX4X'><q id='2LX4X'></q></dir></style></legend>
                <bdo id='2LX4X'></bdo><ul id='2LX4X'></ul>
                1. 本文介绍了从 xib 文件加载 ViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 MyViewController.swift 和一个 MyViewController.xib 展示 MyViewController 的布局.

                  I had a MyViewController.swift and a MyViewController.xib presenting the layout of MyViewController.

                  我尝试了不同的方法来加载这个视图控制器,包括:

                  I tried different methods to load this view controller including:

                  //1
                  let myVC = UINib(nibName: "MyViewController", bundle:
                         nil).instantiateWithOwner(nil, options: nil)[0] as? MyViewController
                  
                  //2
                  let myVC = NSBundle.mainBundle().loadNibNamed("MyViewController", owner: self, options: nil)[0] as? MyViewController
                  
                  //3
                  let myVC = MyViewController(nibName: "MyViewController", bundle: nil)
                  

                  第三个是唯一成功的初始化,但前两个导致错误:

                  The third one is the only successful initialisation, but the previous two are causing error:

                  由于未捕获的异常NSUnknownKeyException"而终止应用程序,

                  Terminating app due to uncaught exception 'NSUnknownKeyException',

                  原因:'[setValue:forUndefinedKey:]: this类与键 XXX 的键值编码不兼容.

                  reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key XXX.

                  这些加载方法有什么问题?

                  What's wrong with those loading methods?

                  推荐答案

                  Swift 3

                  let myViewController = MyViewController(nibName: "MyViewController", bundle: nil)
                  self.present(myViewController, animated: true, completion: nil)
                  

                  或推入导航控制器

                  self.navigationController!.pushViewController(MyViewController(nibName: "MyViewController", bundle: nil), animated: true)
                  

                  这篇关于从 xib 文件加载 ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  iOS AutoLayout - get frame size width(iOS AutoLayout - 获取帧大小宽度)
                  Auto layout constraints issue on iOS7 in UITableViewCell(UITableViewCell中iOS7上的自动布局约束问题)
                  How to resize superview to fit all subviews with autolayout?(如何调整超级视图的大小以适应所有具有自动布局的子视图?)
                  Springs in Auto Layout: Distribute views evenly, with constraints, in Xcode 5(自动布局中的弹簧:在 Xcode 5 中使用约束均匀分布视图)
                  reloadData() of UITableView with Dynamic cell heights causes jumpy scrolling(具有动态单元格高度的 UITableView 的 reloadData() 导致跳跃滚动)
                  What is NSLayoutConstraint quot;UIView-Encapsulated-Layout-Heightquot; and how should I go about forcing it to recalculate cleanly?(什么是 NSLayoutConstraint“UIView-Encapsulated-Layout-Height?我应该如何强制它干净地重新计算?) - IT屋-程序员
                  • <bdo id='AaShF'></bdo><ul id='AaShF'></ul>

                        <i id='AaShF'><tr id='AaShF'><dt id='AaShF'><q id='AaShF'><span id='AaShF'><b id='AaShF'><form id='AaShF'><ins id='AaShF'></ins><ul id='AaShF'></ul><sub id='AaShF'></sub></form><legend id='AaShF'></legend><bdo id='AaShF'><pre id='AaShF'><center id='AaShF'></center></pre></bdo></b><th id='AaShF'></th></span></q></dt></tr></i><div id='AaShF'><tfoot id='AaShF'></tfoot><dl id='AaShF'><fieldset id='AaShF'></fieldset></dl></div>
                          <tbody id='AaShF'></tbody>

                        <small id='AaShF'></small><noframes id='AaShF'>

                        <legend id='AaShF'><style id='AaShF'><dir id='AaShF'><q id='AaShF'></q></dir></style></legend>
                          • <tfoot id='AaShF'></tfoot>