UIPickerView is not being dragged onto header file - ios

I keep trying to use CTRL-Drag from the uipickerview to the ViewController.h but its not creating the object definition in the header file. What do I do?

Make sure that in your xib/storyboard you have set the correct class in the identity inspector. From the drop-down menu, choose the correct subclass that you have created for your view.

Related

Unable to Set Referencing Outlet

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

can I create a .xib from an implementation file?

I have a project that has the header and the implementaiton files and loads a plain old UITableViewController from the .m but I have no way of configuring the View (I would like to do stuff like ad buttons and text fields onto the view instead of just having a table), should I create a .xib file so that I can modify the view? (Reason I don't just start a new project is that the current project has a bunch of other stuff like OAUTH processes that kick off at the AppDelegate stage to log a user into a system - and I need this functionality). So my question how can I create a .xib from the existing .m .h files and then add other objects which I can then code for.
An answer from this similar question:
"Here's a more step-by-step way to associate your new UIViewController and .xib.
Select File's Owner under Placeholders on the left pane of IB. In the Property Inspector(right pane of IB), select the third tab and edit "Class" under "Custom Class" to be the name of your new UIViewController subclass.
Then ctrl-click or right-click on File's Owner in the left pane and draw a line to your top level View in the Objects portion of the left pane. Select the 'view' outlet and you're done.
You should now be able to set up other outlets and actions. You're ready to instantiate your view controller in code and use initWithNibName and your nib name to load it."
If it's a UITableViewController, simply create a new XIB file via Xcode (File -> New -> iOS -> UserInterface -> View) and then add set the file's owner to your subclassed UITableViewController.
You'll likely want to re-do how the user interface looks -- in terms of dropping objects like the table view and buttons or whatever else -- into the XIB's view. It'll certainly save a lot of time versus trying to debug programmatically creating and adding subviews and actions.
And once that's in place, you can then make IBOutlets and IBActions to your heart's content.

XCode will not bind nib and source header file with control click

I added a custom view controller class with interface (.h), implementation (.m) files, and UI (.xib) to an existing project.
When I ctrl-click and drag between the nib and the interface, it will not place an outlet or IBAction when I drag, so I can't link a UI element to a property. Also, XCode does not bring up the corresponding interface file when I view the nib in assistant editor mode.
Note: I changed the name of the custom class. I changed the filename and the references to it in the source.
Make sure you click on file's owner on the left and then in the identity inspector on the right, put in the custom class. You should then be able to make connections.

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