gpt4 book ai didi

ios - 从 xib 文件加载 ViewController

转载 作者:IT王子 更新时间:2023-10-29 05:05:31 28 4
gpt4 key购买 nike

我有一个 MyViewController.swift 和一个 MyViewController.xib 来呈现 MyViewController 的布局。

我尝试了不同的方法来加载这个 View Controller ,包括:

//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)

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

Terminating app due to uncaught exception 'NSUnknownKeyException',

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

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

最佳答案

swift 3

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

或插入导航 Controller

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

关于ios - 从 xib 文件加载 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37046573/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com