Unable to Set Referencing Outlet - ios

I am unable to set a referencing outlet for a text field I have created. I am trying to do this via Ctrl-Drag. Can anyone advise? I have set the delegate as the View Controller. In general, I only have one view which is populated with a few text fields and I have written the following code for the ViewController.h which is what I'm trying to set up as a Referencing Outlet:
#property (weak, nonatomic) IBOutlet UITextField *userIDText;

First, make sure the control you're dragging from is the same class as the outlet (in this case, UITextField) or it could be a subclass of that class.
Second, make sure control's parent view is a subclass of the file you're dragging to.
Third, make sure the file you're dragging to is saved. This is the most common problem I run into. Go to the source file you're dragging to and push Cmd+S to save.
Fourth, when in doubt, Cmd+Shift+K to clean, Cmd+B to build, then try again. If that still doesn't work, restart Xcode. And if it's still not working, go back through the checklist.

In my case, to be able to create a referencing outlet,
I had to open the Storyboard.
Click on the top View Controller element (left panel in the Storyboard)
In the Identity Inspector (right panel), I had to select from the list my custom view controller class before I could drag and create the referencing outlet in it.

In my cace,(swift3)
1.right click on the storyboard.
2.Ctrl-Drag from black window and ReferencingOutlet to View on the storyboard.
enter image description here

Related

Cannot create outlet connections to subviews in Interface Builder (Xcode 5)

I know this appears to be a duplicate of some other questions, but the answers are not working for me.
I have created a single view app.
In the storyboard I added a subview to my main view.
I have a label on my main view and another label on my subview.
I have created a class of type UIView and added it as the custom class for the subview.
I can ctrl-drag my label on my main view to the main view controller class. But when I try to ctrl-drag my label on my subview to my custom class, I cannot get the connection to occur.
I have even typed the property information and tried to make the connection manually to no avail.
Things have changed a bit in the latest version of Xcode's Interface Builder. Can somebody tell me what I am missing? There is literally no code here. I am just testing trying to connect outlets to a subview with a custom class.
The first image shows that I have set up the custom class and added a property but I cannot make the connection.
The second image shows the main view label is connected in the main view's controller.
The third image shows that there are no outlet connections for the subview's label.
You can manually write the IBOutlet property declaration in the #interface of the custom view subclass, and assuming you've defined the base class of your subview in IB, then you can drag from the outlet circle in the code back to the control in the scene.
Or, as you point out, Warren Burton suggested both this technique and another in his answer to this other question, Can't Wire to Subview in IB.
The issue has to do with the File Owner of the View Controller. It is probably set up as being IOViewController, thus you can only make property connections in that .h file.
What you can do, is create another .nib file for the subview and put the subview in there. Then in that .nib file, make the file owner IOSubview. Property connections will work just fine there. Then just add the subview to your IOViewController programatically. Just remember to load the nib file from bundle first.
This is what I did (in Swift):
I Created a new ViewController (e.g. class MyViewController: UIViewController {})
In StoryBoard, I expanded the 'Scenes' (i.e. the tree view of all UI components) and selected 'MyViewController'
Using the 'identity inspector' I assigned the 'MyViewController' class (as oppose to the default UIViewController)
After that I was able to assign an action.
I suspect that for Obj-C it is similar process.
You don't create outlets in the subclass, you create the outlet on the view controller it is on. You need to #import the subclass into IDViewController.h and create an outlet there.
IDViewController.h
#import "IDSubclass.h"
...
#property (strong, nonatomic) IBOutlet IDSubclass *outletName;
Zoom your storyboard to 100%. If you zoom out, to say 50%, then the outlet connection won't work.

I can't create an outlet in Xcode 5

I am trying to link a create an IBOutlet for a UIWebView Element, however whenever I hold down control and drag from the Storyboard to the ViewController.h file, nothing happens and an outlet is not created. I already have an outlet in this file, however, I would like to create another one. Whenever I go to the view controller for the previous outlet and hold control and drag the element to the ViewController.h file a new outlet is created. Is there a setting that I have enabled that stops this shortcut from working. Is there another way to create an outlet for ios in Xcode 5.0.1 on Mac OSX 10?
Fixed issue. The class of the view controller was UIViewController not ViewController. This meant that the ViewController.h and .m files were not showing up under Automatic. Once changed I could view the ViewController.h and .m files and create outlets in them.
I recommend not using storyboard, while it is a lot easier to use, it doesn't let you do many things. To create a new outlet, go to where you want to create it (this will most likely be a header file) and then type: IBOutlet yourOutletType *yourOutletName so to create a UIWebView you would type:
IBOutlet UIWebView *myWebView
and to create an outlet, such as a UIImageView, you could type
IBOutlet UIImageView *imageView
just remember to hook it up in your .storyboard file.
Again, I recommend not using storyboard, it IS a lot easier, yet it really has lots of limitations

how can i get the object of a button created with storyboard

I created a button on a view controller by dragging the icon of button in storyboard. I thought this would generate an object. is there an approach that I can get the id, i.e. the object of that button? Is there a method that we designate a label or identifier for that button and we can refer to it with certain methods?
Thanks in advance for answering.
When you drag a button from the object library onto your storyboard's scene, when that scene is instantiated at runtime, the object associated for that button will be created. If you want to have a reference to that object so you can interact with it programmatically, you can open the assistant editor:
You will want to make sure you set the custom class for your view controller and you simplify your life a little if you tell your assistant editor to "automatically" select choose the right associated .h file:
You can then control-drag (or right-click-drag) from the button down to assistant editor window and create either an outlet (an IBOutlet) or an action (an IBAction):
By doing that, you then have a reference to the button object that is created when the scene is instantiated.
Open Assistan Editor (Split View, so that you see Interface Builder on the Left and Your View Controller on the right.)
Ctrl-Klick & Drag on the button and drag it to the Controller (you'll see a blue line).
An IBOutlet will be generated in your ViewController and you can access it.

How do I add a custom class to a storyboard?

I am currently trying to implement a custom radio button class that I have been messing with (located at https://github.com/t4ku/RadioButtonWithUIKit). This radio button solution draws everything programmatically.
I was wondering if there is a similar solution using buttons that were added via Storyboard. I already have my design exactly how I want it through Storyboard and would much rather somehow "link" the buttons with my radio button class.
Any newer ideas or suggestions would be greatly appreciated.
You can change the class of an object on Storyboard in the identity inspector (you can manually enter the class instead of relying on the drop down menu). You can then link the object however you like.
If Storyboard doesnt accept the RadioButton class for some reason you could also create a custom class of UIButton that would inherit from the RadioButton class and then use that in the same way.
That control is based on UIView, so in your storyboard just add a new View object, select it, and then set the class (at the top of the image) to RadioButton:
You won't be able to see anything but a blank view where you place it, but it will work properly when you launch the application. This will at least make it easier to resize, position, etc.
If I understand your question right, to refer to a button added to a storyboard programmatically, you have to link the variable name in your .h file to the actual button in your .xib file. If you add the following line to your .h file
#property (nonatomic) IBOutlet UIButton *theButton;
Then when you return to the .xib, there should a yellow cube (file's owner) to the left of the storyboard panel. If you right click on that cube, you should get a list of outlets. At the end of the line that has your button's name, there should a circle. If you Ctrl+Click and Hold and drag it to the button in the storyboard, it should like the variable in the .h file to the button in the storyboard.
So now when you refer to the variable name you created, you will be referring to the button in the storyboard.

It won't allow me to create an outlet

I've got a Table View Controller object in my Storyboard, but I've made it a custom class called StaticDetailViewController, which I created as a subclass of UITableViewController.
However, when I go to drag from the view to the .h file in the Assistant view, no connection option appears. Why is this?
You have to open and close your curly braces for your #interface in the .h file. For some reason it won't let you control drag using the assistant editor unless you do so... (screenshot)

Resources