Link view button with the code - ios

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.

Related

Can you add a custom button to the Utilities Panel in Xcode?

Just wondering if it's possible to add a custom button to the Utilities Panel in Xcode that you can drag it into a storyboard scene and have certain aspects already set, color, font/size, gradient etc.?
You are describing a custom xib file containing a view and its subviews. You then load the xib and stick the view in your interface in code, wherever and whenever you need it. Okay, you won't be able to see the effects of that within the storyboard, but it solves the problem extremely neatly.
Another possibility, if this is just about a button and nothing else, would be a UIButton subclass where the button configures itself to have the features you want.
But there is no way to drag-and-drop a custom button from the Object library into the design canvas. What's in the Object library is what's in the Object library and you can't change that.

Can`t drag #IBOutlet from swift file to storyboard ViewController in Xcode 7.2

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 can not connect view controller to code using windows keyboard

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

NSObject instead of the header file

I made an simple UITableViewCell. I put there image view and an label.
I'm trying to drag them to the header file and then use them.
But once I'm clicking on the tuxedo icon I'm getting an NSObject.h instead of WorkoutCell.h .
Here is a picture:
(source: gyazo.com)
I'm trying to add the label and the image view. but I'm pretty new to ios/iphone/xcode so if there is any other way to do it without dragging it (with the ctrl key ofc) to the header file. please let me know .. ;)
and yes I tried to navigate to that header file, but it doesn't appear there ..
May be your cell's class in the identity inspector is NSObject . Change it to WorkoutCell.h . Now try
In your Interface Builder you need to set the custom class of the view.
1) Click on the view in interface builder.
2) On the right pan choose the 3rd tab from the left.
3) Choose the right Custom Class.
I've seen this happen lots of times before.
If you click the third icon from the left of the tuxedo, you can navigate your project files.
From here select the folder your WorkOutCell.h is in.
Maybe someone else can provide a more comprehensive answer as to why this happens, but with this navigation you will at least be able to access your WorkOutCell.h

Using Interface Builder in Xcode 4.6.2

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.

Resources