Neko
Neko

Reputation: 589

UIButton not responding in NavigationController

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

Upvotes: 0

Views: 243

Answers (3)

ahsumra
ahsumra

Reputation: 87

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

Upvotes: 0

dahiya_boy
dahiya_boy

Reputation: 9503

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.

Upvotes: 0

Jake
Jake

Reputation: 2216

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

Upvotes: 1

Related Questions