Swift 连接到xib文件的UIViewController中无法识别子视图

Swift 连接到xib文件的UIViewController中无法识别子视图,swift,xcode,uiviewcontroller,xib,subview,Swift,Xcode,Uiviewcontroller,Xib,Subview,我有一个UIViewController swift文件,它连接到xib文件(我在创建viewController时单击了创建xib)。现在,它无法识别主视图中的任何子视图 当我在调试时编写“po self.view.subview”时。它返回0。所有子视图(表视图、文本视图和标签)=零。我甚至创建了一个新项目,但仍然会遇到同样的错误。 我在这里不知所措 以下是我在AboutsViewController swift文件中的代码: 导入UIKit 进口基金会 类:UIViewController

我有一个UIViewController swift文件,它连接到xib文件(我在创建viewController时单击了创建xib)。现在,它无法识别主视图中的任何子视图

当我在调试时编写“po self.view.subview”时。它返回0。所有子视图(表视图、文本视图和标签)=零。我甚至创建了一个新项目,但仍然会遇到同样的错误。 我在这里不知所措

以下是我在AboutsViewController swift文件中的代码:

导入UIKit

进口基金会

类:UIViewController、UITableViewDelegate、UITableViewDataSource{

@IBOutlet weak var textView: UITextView! 

@IBOutlet weak var contactsTableView: UITableView!

let items = ["Item 1", "Item2", "Item3", "Item4"]


override func viewDidLoad() {
    super.viewDidLoad()
    let NibName = UINib(nibName: "ContactUsTableViewCell", bundle: nil)
    contactsTableView.register(NibName, forCellReuseIdentifier: "ContactUsTableViewCell")

    // Do any additional setup after loading the view.®
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
}
*/
// MARK: - Table view data source

func numberOfSections(in tableView: UITableView) -> Int {
    return 1
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return items.count
}


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    if (indexPath.item == 0) {
        let cell = tableView.dequeueReusableCell(withIdentifier: "ContactUsTableViewCell", for: indexPath) as! ContactUsTableViewCell
        cell.label.text = "HIII"
        return cell

    } else {
        let cell = tableView.dequeueReusableCell(withIdentifier: "ContactUsTableViewCell", for: indexPath) as! ContactUsTableViewCell
        cell.label.text = items[indexPath.item]
        return cell
    }
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if (indexPath.item == 0) {
        return 200
    } else {
        return 86
    }
}
}


确保像这样加载vc

let vc = AboutUsViewController(nibName: "AboutUsViewController", bundle: nil)
self.window?.rootViewController = vc
self.window?.makeKeyAndVisible()

你能分享一个演示吗。xib的文件所有者已正确设置为AboutUsViewController@ManuRaphy设置得很好。当我遵循Shu Khan的回答时,这个问题已经解决了。非常感谢。非常感谢你!我已经试着修了两个小时了。你知道为什么我的旧代码不起作用吗?在app委托中的func应用程序下,我有:if self.window==nil{window=UIWindow(frame:UIScreen.main.bounds)window?.rootViewController=AboutUsViewController()window?.backgroundColor=UIColor.white window?.makeyeandvisible()现在我有了:如果self.window==nil{window=UIWindow(frame:UIScreen.main.bounds)window?.rootViewController=viewController window?.backgroundColor=UIColor.white window?.makekeyeandvisible() }