9

I am building an iOS app and i have most of the code/GUI built (its a single view app). Now i have the .xib and controller.h file next to each other and I want to associate a button click with a certain action. Everytime I try nothing happens. The UI indictor that I am dragging shows up but it wont let me connect to the method. This happens for all the objects/methods.

I have an almost identical project that works just fine too!

Dreken105
  • 149
  • 1
  • 1
  • 10

3 Answers3

20

Select your XIB file and then select "Files Owner" which is the yellow cube. In the Utilities Sidebar, select the Icon with the circle and arrow inside of it (which is the "Connections Inspector"). You can then Control + Drag your to your button.

//// Edit ////

After investigating your project... Pretty sure you deleted a storyboard and then added a .xib but didn't set it's class, or link it's view as an outlet.

To do that:

  1. Select the new view (XIB), then selct the main view, and in the identity inspector, set it's class to your custom class name "AVYSViewController."

  2. Switch to the connections inspector and Control + Drag the "view" outlet to the main view in your XIB.

Also, your project was looking for the MainStoryBoard.storyboard file. So get rid of that setting by selecting your project, then selecting your target, and in the "Summary" tab, delete anything in the "Main Storyboard" field.

Note: I checked to see if your project settings were valid before I deleted the storyboard setting and it returned NO errors, so beware of this problem for future projects.

jhilgert00
  • 5,479
  • 2
  • 38
  • 54
  • im sorry i think i followed you steps correctly i just dont understand the ending. after i got the connection inspector out, what am i dragging to my button? – Dreken105 Feb 02 '12 at 02:13
  • You would be dragging your action, which would be listed under "Received Actions" in the connections inspector. If it's not there, you might have some code problems we should look into. – jhilgert00 Feb 02 '12 at 02:16
  • looks like there is. what do you need me to show you? just the controller.h? – Dreken105 Feb 02 '12 at 02:19
  • If you're trying to attach an action to a button, we need should probably look at the code to both your .m and .h – jhilgert00 Feb 02 '12 at 02:22
  • You can add the code by editing your question (not sure if you know that or not, just trying to help :) – jhilgert00 Feb 02 '12 at 02:23
  • [link](http://bit.ly/wBMC5W) this link is to a .zip of my project if you prefer i add it ill happily oblige – Dreken105 Feb 02 '12 at 02:25
  • btw even though most of the code is implemented I do have to go back and change some things. i just want the buttons to work before i do. – Dreken105 Feb 02 '12 at 02:27
  • hey man i just created a new project and copy/pasted everything into it. Worked like a charm. Idk what was wrong before but thanks a lot for the help. If you figured out what went wrong im sure itll be useful to me, if not someone else, in the future. – Dreken105 Feb 02 '12 at 02:43
  • Yeah, I opened your project, and I was baffled. Went against everything I know. If anyone has had the same problem, it would be awesome to hear a solution to this one. – jhilgert00 Feb 02 '12 at 02:48
  • lmao.. i was just about to comment and say the same thing. Weirdest bug i ever seen. – Just a coder Feb 02 '12 at 02:55
  • Did you, by chance, delete a storyboard from this project and add a new .xib? – jhilgert00 Feb 02 '12 at 03:12
  • A note to future visitors to this page: I solved a similar problem in Xcode 7 by (a) making my view "initial view controller" with the Attributes Inspector, and (b) changing the custom class to "View Controller" in the Identity Inspector. – Michael Stern Oct 08 '15 at 19:07
1

I think i'm reading the same book as you (Big Nerd Ranch's "iOS Programming"). If so then yeah, I had the same issue as you. Admittedly I am using my laptop to vnc through to a mac box to work on xcode, so I thought it was vnc not capturing the keyboard properly, but turns out it wasn't vnc as I could right-click/cntl-click drag on other things.

Admittedly again I didn't do much research on why it wasn't working, but in the meantime I just right-clicked on the button, which shows the events that the button emits, then click-dragged the "Touch Up Inside" event and dropped it on the controller/owner, which then displayed the actions/methods to hook the event to. If you look on page 17 (if you are reading the same book) then that is the event that was hooked up.

Sorry if there are any obvious glaring errors with what I just say, have only just started reading this book today after a big lunch.

DrunkenBeetle
  • 267
  • 4
  • 2
0

I think you should rephrase you question.. It's very confusing. But if i understand what you are saying, you now have the files open side-by-side in the using the assistant editor. The Xib file on the left hand side, the .h file on the right. correct?

Now you are trying to link the event in the control, to the method you have defined in the .h file. right?

So if you are in fact seeing the methods in the .h file that you want to link to, but the editor is not letting you link to it, then chances are that you have have the xib file side-by-side with the wrong .h file. Are you sure that the .xib file and the .h that are side-by-side are both called controller ? controller.h and controller.xib ?

Just a coder
  • 15,480
  • 16
  • 85
  • 138
  • yea definitely the right files and you interpreted the question correctly. sorry for the confusion. – Dreken105 Feb 02 '12 at 02:11
  • Ok if they are the same, then what control are to trying to link the method to is it a button? if it is a button, be sure to have to method defined as **- (IBAction)myMethod:(id)sender;** Are you doing that? – Just a coder Feb 02 '12 at 02:16
  • yep: `- (IBAction)showQuestion:(id)sender; - (IBAction)showAnswer:(id)sender;` – Dreken105 Feb 02 '12 at 02:21
  • [link](http://bit.ly/wBMC5W) this link is to a .zip of my project if you prefer i put it online, i can do that – Dreken105 Feb 02 '12 at 02:24