Xcode issue - cannot connect button to object - iphone

I seem to be having an issue. The tutorial I am following from Apple's Dev Center says:
Control-drag a connection from the
Convert button to the
ConverterController instance in the
nib file window.
A black box will pop up similar to
the one we used to connect outlets.
Choose convert:.
Save the nib file.
I usually hold ctrl and drag the mouse from one object to another. However, when selecting a button from my User Interface and trying to drag to an Object in the xib window (this is all in the Interface Builder), the object will not highlight. It just won't let me do it!
Any ideas why this is happening?

you can use the "tree" map of all the objects in your nib file so it is easier to select one. this is helpful if they are on top of each other, hidden, or otherwise difficult to click directly. in xcode 4, there is a little triangle button along the bottom left of the nib view; if you click it, a sidebar opens with a text outline of all your nib's object. you can click the button in this list so it highlights, then control-drag to your file owner to attach it to a method you have written. the sidebar is also useful if you want to re-order objects in a view or subview, to make some on top of others.

Right click the file owner file a pop up will appear in front of you their you can see various action methods that you have in your project.
select a particular action method and then assign it to the appropriate button on which you want to call the appropriate function.

Related

Why is the IB Action set to exit as object?

I am creating an app that requires notifications. I created a settings page with a switch to toggle notifications for the application. I tried to link the switch to ViewController2 using an #IBAction, but it keeps connecting the object to Exit, instead of ViewController. I am getting really frustrated because the #IBAction won't stay connected. I am not sure what is going on, but if I could get help that would be amazing.
The images are linked down below to Imigur.
This is the connection to ViewController2
This is what occurs when I connect the IBAction to ViewController2
You can see there is no action option for the connection in this image.
When you attach #IBActions (or #IBOutlets), you do not want to attach them to Exit on the View Controller.
Follow these steps to add an #IBAction:
1) Make sure your View Controller's class is linked to your file, then go into the Assistant Editor making sure you selected Automatic.
2) Hold Control (^) and drag the button to your ViewController class.
3) Add the button as an #IBAction. - It's also recommended to use UIButton as the sender, instead of Any.
It should look like this:
If you have questions, let me know!
The problem might be that you are supposing you can form an action connection from a UISwitch in the scene of one view controller to a different view controller. You can't. You can form outlets and actions only between a view controller and the interface inside the same scene of the storyboard.
Click on the top bar of your problematic ViewController (the overview of what is getting displayed on screen), click the top left icon (called View Controller).
On the right click "Show The Identity Inspector" icon and you should see class. Change the text to 'ViewController'. Hopefully it should auto fill.
This will solve the problem.

How can I find the file my storyboard outlet connects to?

This may be a silly question.
I know I can easily go to my storyboard from my outlet e.g.
Is there an easy way to do the reverse? I'd like to go from my storyboard element to my swift file, specifically the line of code where the outlet is declared.
I'm not aware of any shortcut link back to the declaration of an outlet. A couple of alternatives are:
Use the Assistant Editor (it's the middle button below with the two overlapping rings) while you have a View Controller or an element within it selected in a storyboard. It will load up the accompanying class in a panel beside the storyboard view.
Select the View Controller itself out of the hierarchy, go to the Identity Inspector on the right, and tap the little gray circle icon with a white arrow in it beside the class name. That will take you to the class file in the main editor.
Those are the only two methods I know of for getting to the associated class.
Select the element and then click "Show the Assistant editor" at the top right. It will take you to the correct class, but not to the exact line it is declared on.
Select element:
Click "Show the Assistant editor":

Why XCode 4 doesn't create XIB file when using storyboard?

Why can't XCode 4 create XIB file while using storyboard: is it 2 incompatible models ? For example all tutorials about hiding keyboards seem to require XIB file:
http://www.techotopia.com/index.php/Writing_iOS_4_Code_to_Hide_the_iPhone_Keyboard_%28Xcode_4%29
Here is an update to the link in the question:
Having written the code for our method we now need to wire up our user interface so that it gets called at the appropriate time. We will perform this task in Interface Builder, so select hideKeyboardViewController.xib once more.
The equivalent of this now is to click on storyboard, and then click the hidKeyboardViewController in the storybaord window.
Select the text field in the view and display the Connections Inspector (View -> Utilities -> Connections Inspector) in the right hand panel.
The equivalent of this now is to Right click the text field.
Click on the circle to the right of the Did End on Exit event, drag the line to the File’s Owner icon and select textFieldReturn from the list of available methods.
Equivalent here is to click the circle, as mentioned, then drag the blue line to the orange box at the bottom.
Its the same, inside the storyboard you will see your views and you can do the same as you did when you were working directly with .xibs
Treat the "scenes" in the storyboard as if they were XIBs. You can layout the screen, add elements, and link them up to their respective ViewControllers. Any code you need to run should be in a ViewController, and then in the Storyboard you can indicate that a particular scene is related to that ViewController.
For your question about hiding the keyboard, you'll need to have a method in your ViewController that includes a line of code:
[myTextField resignFirstResponder];
...where myTextField is a UITextField, UITextView, or other object that requires a keyboard.

Round Rect Button connecting to ViewController.h

So, this is kind of hard for me to explain, but i will do my best. I am most likely making a simple mistake, but i cant figure it out. So, im on my mainstoryboard, with a round rect button on the controller. I open the dual view editor and open up the viewcontroller.h file. Now, i should be able to press control and drag the button connection in the .h file, but i cant. It wont give the option to. Does that make sense?
Any ideas?
http://www.youtube.com/watch?v=62Xfn5oAjw0
Edit: For example, i need to do the part at 3:08, but it won't allow me to do that.
Edit 2: Ok. So, i put the button on a single view controller, and everything worked the way it should. BUT, when i put the same button on a tab bar view controller, it doesn't play the sound it should when pressed. The sound played when it wasnt on the tab bar controller just fine though.
EDIT: I watched the video and I know what you're doing. You're trying to create an outlet. When you right click the button there'll be a circle that says "New referencing outlet". Try dragging that circle to the viewcontroller. Otherwise, just type what comes up after he does that manually. Easy.
It should already be connected automatically. You never actually drag the button to the view controller. The view should already be connected and therefore any part of the view is connected. However, if you're having problems in the future, try this to sort of start over.
What you're going to want to do is go up to file>New File
Then you're going to want to select a new view controller, and make sure you tick the box that says "Include a XIB" or something similar.
After that, it will make all the connections you need. Any part of the view will automatically connect to the view controller, and all you'll need to do is create the IB actions to preform things in the interface and connect them to buttons when you're ready.
You have to set the viewcontroller as the file owner of the view. This is done in the story board.
I don't understand why you'd want to ctrl+drag the button to your ViewController.h . If you wanted to link the button to a ViewController in the storyboard, then you just ctrl+drag it to that ViewController. I may not have understood your question, but I think this is what you want.

Connecting file owner to app delegate

At some point I deleted the Object to my appdelegate file for some reason from the XIB. I added a new object, and selected MyAppNameDelegate as the class. However, it's not connected to file owner, and I dont seem to get the option when right clicking and dragging. I think this is causing me some runtime issues. Any ideas?
If you are referring to your MainMenu, the the file's owner is an object of type NSApplication.
In IB, you should select your file's owner, access it's 'delegate' outlet and drag it (as to draw a line) to your app delegate. This will restore the connection.
Check also that your file's owner has got the NSApplication class type. Maybe it got changed somehow.
I had this same problem. I found a lot of half-answers on different threads, so I decided to put them together here.
Drag an NSObject instance from the Objects palette to the area below "Objects" where the objects for your xib are listed (click on the triangle at the lower left if you can't see it) for MainWindow.xib. The object should show up as a solid orange box.
Select this newly-created NSObject, and change its class to the name of your new App Delegate (whatever the file name is without the .h or .m), using the Identity Inspector. This should be an option in the pop-out list.
Control-drag from the File's Owner to the new object, which should not be displayed as " App Delegate", and select delegate.
You will also probably have to reconnect the Window (and possible other views) to your new delegate. Do this by dragging from the App Delegate to the Window and selecting window.
Hope this helps.
This was driving me nuts also.
I marked +1 above, the answer does in fact help, the answer is cryptic, so this will help explain in finer detail how to get a delegate or another connection that won't link directly into the file using the "Assistant Editor" view.
right click = control key + left click.!
IN XCode 4. Select any of your XIB files. Say for a UIScrollView you added, you want to set the Delegate for it. Well unlike the prior IB where you just open up connections inspector, and drag a connection to the file. Its actually just the same here. BUT a difference.
(NOTE:The dock is panel 2 from the left. Only with a XIB open)
Open up the Dock > http://developer.apple.com/LIBRARY/IOS/#documentation/ToolsLanguages/Conceptual/Xcode4UserGuide/InterfaceBuilder/InterfaceBuilder.html
There is a small triangle arrow there at the bottom of the Dock.
At the very top of the Dock is "Files Owner", without the dock opened, it is the white box with orange trim.
Select the view or what ever needs delegate access to the File (UISegmentControl drove me nuts on this too), right click and drag a connection on "New Referencing outlet" to the Docks "Files Owner", and a list will pop up.
Like wise, you can right click on the "Files Owner" and remove connections easily there, or make new ones.