I have just updated my Xcode to the latest version and the IB is quite different from the version I used before. I've created some IBOutlets and whereas before I could drag from the Files Owner to the component to marry up my IBOutlet from my .h file. In the new version there are three icons one of which is the Files Owner but it doesn't seem to do anything. How do I marry up my IBOutlets in the new version?
Press and hold 'Ctrl' key while dragging. You'll see a blue line. Drag the blue line to the item you want to connect and when you release you'll get a popover showing your outlets.
Alternatively, show the code file and the XIB file beside each other (using the assistant editor). Each outlet definition will have a circle beside it in the trough. Drag from there and you'll get the same blue line to connect with but this time Xcode knows the outlet so it just connects it as soon as you drop on the target view.
Related
I use Xcode 7.2
I can use Control+drag to swift file to create a #IBOutlet
But I can't drag #IBOutlet in swift file to storyboard. Here I don't use any other key, just drag.
Actually when I moving mouse to the spot before #IBOutlet, nothing happened and when I trying to drag it a breakpoint added.
1.I`m sure I use the right Class name
2.My project is not in a strange path or name
don't use Control, only drag with mouse from circle icons.You can see in the picture below. Circle icons in red box
Changed Behavior
The behavior has changed in new versions of Xcode (I'm not certain but it might have been since 7+.). Older versions of the product might still have the gutter shortcut working.
Now you have to either open the Connections Inspector or right-click on the view controller in the Document Outline. Once open, drag from the defined IBOutlet to your UIView subclass (UIButton, UITextField, etc...)
Connections Inspector
Controller View
Official Guidance
Search your local help for: Interface Builder Connections Help: Creating an Outlet Connection. You will find these are the only methods that now work. The gutter shortcut does not work.
Nota Bene:
You can confirm this behavior and other changes to Xcode shortcuts by
choosing the following menu Help > Xcode Overview and
taking a look at Part V: Building a User Interface, section Connecting Objects In Code.
I'm new to iOS XCode6 ,trying to create a single view app . When I try to create an outlet connection to the label by drag and drop , nothing shows up as you see in the picture below. I did search the web all over to find an answer but nothing worked. I'm working from a text book which is made for beginners,following all instructions and nothing there mentioned about this issue. Any help will be appreciated.Thanks .
What you select is a LaunchScreen. You can not drag and drop from there into your viewController
Select the storyboard,set the class to the right viewController,then you can drag outlets
Set the class to the viewController here
Then you can drag outlets like this
I started to learn IOS development. I am going through a video tutorial. The instructor is connecting the Hello World to the code by pressing control and using the mouse, as you can see in the screenshot :
I have windows 7 machine. I rented a mac VM from xcodeclub. When I tried to press control and connect the viewcontroller to the code by dragging mouse as done by the instructor, it do not connect. I am using windows keyboard. So how to do this ?
Is any other way to do this ? Or I have to use some other key + mouse drag ?
Fix. Try right clicking on the label and dragging from new referencing outlet.
Otherwise, check to see if your view controller is the correct class. Click on your storyboard file (probably called main.storyboard or something similar) and select the graphical representation of your view controller. Then, on the right hand side click on the small icon that is the 'identity inspector'. Make sure under custom class it displays UIView. If it doesn't, change it to UIView and try again.
If that doesn't work make sure you're dragging the blue line across the screen so that when you release it you are between the #interface and #end lines of code. Like this:
#interface
// drag it here...
#end
From what I can tell there are some challenges people are having in XCode6 in terms of wiring up outlet collections. I just wanted to see if i'm doing this right or what I need to do correctly! I reviewed here Can't hook up an outlet collection in Xcode 6 using storyboard as well as other areas, but I wanted to be more basic about this first.
I have 7 images on a screen. I'd like to iterate through all of them in a loop or something. I read an outlet collection would be a sensible way to do this. To create an outlet collection, I am doing this:
While splitting the screen (storyboard on left, assistant editor on right) I control+click on one of my 7 images, and drag it into the view controller code on the right. This will prompt me to create an outlet, or outlet collection (I select outlet collection).
Now that this is done, a circle appears in the left margin next to this variable indicating that the image is associated with that variable. If I hover over the circle, the first image lights up.
What you're supposed to do (can someone confirm this please??) is you just hover your mouse over the circle, and a + symbol appears, and all you do is hold down the left mouse button, and drag over to another image (for example image#2), and it should automatically add that to the collection. The idea is to simply drag to each image so they are all added.
Is that right in step #3 above? Is this the normal way you would add items to a collection? Drag from the + to the image within your controller? For me, when I do this, the line appears, but it doesn't seem to respond to connecting the line to anything. I just hover it over the images, and it doesn't highlight the image or select it or anything, and when I let go, nothing happens.
I'm still somewhat new to this - what am I doing wrong?
Thanks so much for your patience/help!
OK I had the same issue and I think I have just found a workaround
1) Do steps one and 2 with the first image
2) Now repeat exactly what you did using the second image - drag and drop just below the first outlet collection (this would simply create a second outlet collection use exactly the same name )
3) Now Xcode won't like it as you have two outletCollections with the same name. Now comment out the first one
4) Now you only have one outlet collection. And it would be wired up to both your images. confirm it by hovering your mouse pointer over the little 'circle' next to the IBOutlet to see your images being highlighted.
This seems to work for me. So hope this helps :-)
There is an error with Xcode and Interface Builder that causes problems with outlet collections. You are doing it right, Xcode is problematic.
A workaround is to:
Go to your DerivedData folder (Xcode preferences -> locations)
Clean build folder from the Product menu while holding option (alt) button
Quit Xcode
Delete the folder starting with your app's name in the derived data folder
Go to your xcodeproj file, right click it, show package contents.
Delete the xcuserdata folder (warning: don't touch the others!)
Open Xcode again.
When you delete user data, window positions etc. will be reset to defaults and breakpoints will be deleted. Your project should work smoother (after a few seconds of re-indexing) and outlet collections should work properly.
I have had some success by just changing my workflow as follows (no need to restart Xcode).
First, create the outlets in code in the controller class file.
Second, drag from the objects (in the outline view of IB) to the controller, or back (for actions).
This has always worked without fail. It is slightly more effort, but actually negligible. Definitely an Xcode bug.
I am learning IOS development, and I have a question about the connection with the view (designed on Interface Builder) an my controller, that has the code. How can I connect both and make things like set a properties, etc.
There are a few ways....
The quickest is with Xcode 4+ using Interface Builder and Assistant view.
Open your NIB (xib file) and touched the Assistant view button at the top right of the screen, looks like a tuxedo (outlined in red in screenshot below). This will load the associated interface/header file for this NIB.
Select your button and hold the CTRL key and drag to your header file and point where you want the declaration to be placed as seen below.
Release the mouse and setup the connection as shown below.
Once this is completed you will have a method added to your implementation file where you can write your code for what happens when the button is touched.