IBOutlet not connecting in SWIFT

2019-07-24 22:46发布

问题:

All,

I have this in swift

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

    @IBOutlet var tableView: UITableView!

So if i go in the storyboard, I should be able to see that, and I should be able to connect it like this :

So I should be able to go to 'New Referencing Outlet' and drag it on the view controller (yellow tab at the top) and I should see 'tableView' and connect it. This doesn't happen , I am confused why !

回答1:

Do no type following line in advance.

@IBOutlet var tableView: UITableView! // <-- this line

Instead, add a UIComponent in your storyboard first and then using "assistant editor" drag the connection link in your swift file.



回答2:

On the picture you posted I can see you are looking for IBOutlet, but you selected the tableView not the whole controller.

Click on the white status bar (where yellow - controller and 2 oranges - responder and exit buttons are) then you will see your IBOutlet