0

I create a XIB file and there are a NavigationController in the xib file, a UIViewController in the NavigationController. Then I drag a button into the UIViewController. I want to connect the button and the UIViewController but I can't. I can only drag a line from the button to the navigationController and the button is not responding to the action in the NavigationController. I don't know why.

Can someone tell me why? I want to know why I can't connect the button and my UIViewController (only can connect to NavigationController). How to let the button work?

enter image description here

enter image description here

enter image description here

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Neko
  • 581
  • 1
  • 9
  • 24
  • 1
    Your file's owner must match with the filename. – dahiya_boy Feb 26 '18 at 05:07
  • you are right @dahiya_boy I tried change the file's owner from navigationController to UIViewController, and than I can connect the button to the navigationController's root viewController. Thanks a lot. but there still a problem. if I don't change the file's owner , I can drag a line to add a click action to the navigationController's file. but it doesn't work.(like the third pic i have post above) – Neko Feb 26 '18 at 05:41

3 Answers3

1

I have had a similar issue. You have a couple of options.

First you can find the button (or label in my case) on the left side of the storyboard and you can right click then drag to the code in the assistant editor

enter image description here

You could go into the assistant editor where the Action or Outlet is, find the circle next to it, left click and drag to the button or label in the list view that I showed before.

enter image description here

And the other option is to find the item you want to link in the storyboard and select it. Then select the 'Selections Inspector on the top right. In there you can click and drag from the circle and see everything that is connected. You can also see EVERYTHING in the VC if you select the ViewController in the story board and look at the Selections Inspector.

enter image description here

Jake
  • 2,126
  • 1
  • 10
  • 23
  • thank you Jake, but I think it's because I have set the wrong file's owner. I can only drag a line to the xib file's owner right? and the second mistake , I think the button is added on the viewController, so even if I can add the action to the navigationController, but the navigationController can't responding the event. – Neko Feb 26 '18 at 05:45
  • Ah, yea those pictures weren’t available when I posted this – Jake Feb 26 '18 at 05:46
  • my mistake, don't know how to add pics. any way , thanks again. – Neko Feb 26 '18 at 05:51
0

In your case Your file's owner must match with the filename..

Now as you per your comment

File owner is the file which own's this xib. The File Owner is an instantiated, runtime object that owns the contents of your nib and its outlets/actions when the nib is loaded.

If your file owner does not match it does not connect any outlet. In your case, its hard to say for me w/o knowing how you created your file and nib.

For further info you can ask or refer below links.

dahiya_boy
  • 9,298
  • 1
  • 30
  • 51
0

Well you are right about in the xib if we set configuration like yours then it doesn't allow us to draw a connection to the chidVC! but it allows you to draw an outlet to your NVTest

To connect directly using ctrl+drag from button to your chidVC please set the file owner to chidVC in your Xib file.

After you are able to connect please use following code to load:

let nvc = Bundle.main.loadNibNamed("YOUR_XIB_NAME", owner: nil, options: nil)?.first as? NVTest
ahsumra
  • 87
  • 10