UITableView from Storyboard is always nil

I am having a very frustrating issue from a very simple situation. I just want to connect and populate a UITableView from the Storyboard. Below is a picture of my situation.

StoryBoard和UIViewController类的视图

As you can see, I just have a normal UITableView in my Storyboard, with a normal UITableViewCell set up as a prototype. The prototype cell has a Cell Identifier and the UITableView is properly hooked up to the IBOutlet in the UIViewController class. The UIViewController is assigned to be my UIViewController subclass in the Storyboard. Yet, the UITableView is nil in viewDidLoad(), and it is nil everywhere outside of viewDidLoad(), it is always nil. I have redone this three times now. I have restarted XCode, and I have restarted my computer. Is there something I am missing?

EDIT: The solution - Don't load the view controller programmatically in the app delegate... load from the Storyboard. Facepalm.


Override the setter for tableView to check if that is really working.

class MyController: UIViewController {
   @IBOutlet var beaconTableView: UITableView! {
     didSet {
       print("tableView is set")
     }
   }
   .........
}

This will help you debug further about it. If the setter is not called at all. Remove the table from storyboard completely. Add a new one and create IBOutlet connection again. See if that works !

链接地址: http://www.djcxy.com/p/87742.html

上一篇: UITableViewCell子类IBOutlets返回nil

下一篇: Storyboard中的UITableView始终为零