Hi, I currently got a problem with xcode with connecting an outlet or any other code to my stoyboard. How could I fix this problem?
Could not insert new outlet connection
Good day,
This is right out of the book and I to am having issues with the connections everything is set-up and ready to go the fact that I am on a MacBook and can't make the connections using a track-pad instead of a mouse is what I think is going on but this should not be.
I have posted on this issue before, but now i see more people are haveing the same issue.
captbullett
Create Outlets for UI Elements
Outlets provide a way to reference interface objects—the objects you added to your storyboard—from source code files. To create an outlet, Control-drag from a particular object in your storyboard to a view controller file. This operation creates a property for the object in your view controller file, which lets you access and manipulate that object from code at runtime.
You’ll need to create outlets for the text field and label in your UI to be able to reference them.
To connect the text field to the ViewController.swift code
- Open your storyboard,
.Main.storyboard
- Click the Assistant button in the Xcode toolbar near the top right corner of Xcode to open the assistant editor.
- If you want more space to work, collapse the project navigator and utility area by clicking the Navigator and Utilities buttons in the Xcode toolbar.You can also collapse the outline view.
- In the editor selector bar, which appears at the top of the assistant editor, change the assistant editor from Preview to Automatic >
.ViewController.swift
displays in the editor on the right.ViewController.swift
- In
, find theViewController.swift
line, which should look like this:class
class ViewController: UIViewController {
- Below the
line, add the following:You just added a comment to your source code. Recall that a comment is a piece of text in a source code file that doesn’t get compiled as part of the program but provides context or useful information about individual pieces of code.A comment that begins with the charactersclass
is a special type of comment that’s used to organize your code and to help you (and anybody else who reads your code) navigate through it. You’ll see this in action later. Specifically, the comment you added indicates that this is the section of your code that lists properties.// MARK:
// MARK: Properties
- In your storyboard, select the text field.
- Control-drag from the text field on your canvas to the code display in the editor on the right, stopping the drag at the line below the comment you just added in
.ViewController.swift
- In the dialog that appears, for Name, type
.Leave the rest of the options as they are. Your dialog should look like this:nameTextField
- Click Connect. Xcode adds the necessary code to
to store a pointer to the text field and configures the storyboard to set up that connection.ViewController.swift
@IBOutlet weak var nameTextField: UITextField!
the text above is from: the website//* https://developer.apple.com/library/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson3.html#//apple_ref/doc/uid/TP40015214-CH22-SW1