xib文件中的连接视图未显示,并且无显示nil

问题描述 投票:-1回答:1

我的视图已连接到我的ViewContoller swift文件,文件所有者可以,但是对我来说不起作用。视图未出现,并且为零。我上传了一些图片以获取更多信息。我尝试了一切。清理项目,重新加载xcode,删除交付的数据,删除仿真器数据。

enter image description here

enter image description here

enter image description here

enter image description here

ios swift xcode xib viewcontroller
1个回答
0
投票

据我了解,您正在初始化视图控制器,但未从情节提要中加载它。您可以尝试向UIViewController添加扩展以方便加载:

extension UIViewController {
    class func loadFromNib<T: UIViewController>() -> T {
         return T(nibName: String(describing: self), bundle: nil)
    }
}

let vc : Test3 = Test3.loadFromNib()
navigationController.pushViewController(vc, animated: animated) 

参考:https://developer.apple.com/library/archive/referencelibrary/GettingStarted/DevelopiOSAppsSwift/WorkWithViewControllers.html

© www.soinside.com 2019 - 2024. All rights reserved.