UIViewController中的出口在viewdidload中为零 [英] outlets in UIViewController nil in viewdidload
问题描述
我有一个UIViewController,带有一个tableView的插座
I have a UIViewController with an outlet for a tableView
@IBOutlet weak var tableView: UITableView!
当我尝试访问 viewDidload $ c $中的tableView变量时c>它抛出错误,说tableView是
nil
。
When I try to access the tableView variable in viewDidload
it's throwing an error saying tableView is nil
.
似乎在界面构建器中设置了所有内容。 File's Owner的类设置为我的自定义类,并且也设置了tableView出口。这里可能出现什么问题,为什么tableView变量在viewDidLoad中仍然是nil?
Everything seems to be set up in the interface builder. The class for File's Owner is set to my custom class and the tableView outlet is set as well. What could be going wrong here, why is tableView variable still nil even inside viewDidLoad?
推荐答案
你输入的那个出口代码没有创建一个链接?
Did you type out that outlet code without creating a link?
如果你这样做会是你的问题。
返回故事板,切换到助理编辑器模式,从UITableView CTRL + Drag到 @IBOutlet弱var tableView:UITableView!
If you did that would be your problem.
Go back to your Storyboard, switch to assistant editor mode and CTRL + Drag from the UITableView to @IBOutlet weak var tableView: UITableView!
确保你的var左边有一个FILLED IN圆圈,类似于此。
Ensure you're got a FILLED IN circle to the left of your var similar to this.
这篇关于UIViewController中的出口在viewdidload中为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!