How do I connect a pre-made IBAction to my storyboard? - ios

I am trying to implement a dropdown menu I found on github, it has pre-defined IBActions and IBOutlets. How do I connect theses outlets to the storyboard? Ctrl-drag is not working.
I believe my issue is that the file DropdownMenuController will not show up in the automatic section of files in the assistant editor. How would I add files?
Update:
The IBActions just aren't showing up anywhere. Here is an example:
All the outlets and actions that Xcode thinks exist
But here in the Objective-C files are IBActions that don't show up

First you have to set the right View Controller Sub class to the view controller in the interface builder. check the following setting
Now you open the Utilities panels and go to the connections inspectors, not the source files.

Select viewController in storyboard, open utility bar and in connection inspector you will find methods which are mark with IBActions
After drag and drop you will prompt like this
select vc first in storyboard like this

Related

Xcode lost track of corresponding ViewController making a Reference Outlet

I have built a Xamarin iOS app in Visual Studio for Mac using Xcode to edit the UI storyboard. The app runs great. I even have it in Apple Connect and a tester is testing it.
I need to create a Referencing Outlet in Xcode, for a Text Field but Xcode is not doing the right thing when I Ctrl-drag the Text Field control to the corresponding .h file. Here are two descriptions of the problem.
Description I
I have followed the directions here using the Assistant in Xcode.
The Assistant displays the storyboard and a code file side by side, like it should. When I click on a control in the Scene I want to work with (ContactUs) a generic UIViewController (UiViewController.h) displays in the code side. My ThirdViewController should display.
The generic file that displays has this in a comment near the top of the file.
UIViewController is a generic controller base class that manages a view. It has methods that are called when a view appears or disappears.
When I click on my Home Scene the FirstViewController displays in the code side. I think that is correct.
Description II
When I display the storyboard and the FirstViewController.h file side by side - NOT using the assistant - and I Ctrl-drag a control in the Home Scene to FirstViewController.h, Xcode offers the Outlets popup just fine.
When I display the storyboard and the ThirdViewController.h file side by side - NOT using the assistant - and I Ctrl-drag a control in the ContactUs Scene to ThirdViewController.h, Xcode does not offer the Outlets popup.
So it seems that Xcode has lost track of my ThirdViewController.
What do I need to do to create an Outlet in the ThirdViewController.h file using the Ctrl-drag approach?
When you select your controller in the storyboard, did you check the Identity inspector in the right panel to make sure that your class is set in the CustomClass > Class field?

How to navigate from one project storyboard to another project storyboard in Ios

I have two projects in workspace, I want to navigate one project storyboard to another project storyboard.
Use storyboard references. Drag an drop a storyboard reference from the side panel and connect it with your respective view controller. Select the storyboard reference and edit it's properties like the first/main view controller of it. Name the segue as usual and you'll be able to switch between multiple storyboards
P.S: make sure the all your storyboards has their entry points set!!

Storyboard assistant editor for a ViewController opens <projectName>-Swift.h instead of <viewController>.swift

I have a programmatic swift project that I'm converting to Storyboards. A particular interaction is grinding my gears.
When I click on a view controller MyViewController in a storyboard, the assistant editor opens up myProjectName-swift.h instead MyViewController.swift
I know I can click on the nav bar of the assistant editor and select my VC from the automatic drop down list but this is just adding more actions every time I switch VCs in storyboard.
When you set you class to match your view controller, usually the assistant editor will open the right file.
This is how to select the class:
Select your view controller in storyboard
Open the identity inspector
Select the class from the list
That -Swift.h file was generated by swift 2.2 and lives in the derived data folder.
After clearing derived data the problem seems to have resolved itself

Can't drag and drop item from storyboard to viewcontroller in xcode

I started working with xcode a few days ago, and today I tried to connect a textview from the main storyboard to the viewcontroller, but I figured out that its not working.
I am able to ctrl+click to drag the item, but unable to place it in both viewcontroller.h and .m. I double checked that its viewcontroller and not UIViewcontroller, so this is not the case.
I'm using a Yosemite 10.10 mac.
Any kind of help would be appreciated.
Select the ViewController in storyboard and change the name of the ViewController to the name in the .h or .m file and then try ctrl+click and drag
For beginners -- > make sure you have kept the "Ctrl" key pressed down while dragging and dropping onto the code. This can be easily missed.
For me, the solution was to click on the "View" item in the dropdown menu that shows all the subviews for the controller.
Simply clicking on the controller image on the storyboard does not appear to properly "select" the controller for drag and drop abilities, the base view must be selected.
Make sure you're in Assistant Editor Mode (When code and layout editor are side-by-side).
From Apple:
With Interface Builder open in the standard editor pane, select the
control you want to configure, and click the Assistant Editor button
() in the workspace toolbar.
The assistant editor opens your object’s implementation file.
Control-drag from the control in Interface Builder to the
implementation file. (In the screenshot, the assistant editor displays
the implementation file of the view controller for the Warrior
button.) Xcode indicates where you can insert an action method in your
code.
For anyone who is new to XCode this picture might help more:
Select the item in Main.storyboard from the right pane and then set the class for the view in the right pane. Now you can ctrl + drag into your class
After trying all of the other answers, what finally fixed this issue for me is simply restarting Xcode and I was able to see the blue line that indicates where I can place my action method...
Note that dragging to any point in your code doesn't necessarily work. If you've been unable to drag to create the connection in one spot of your code, try dragging to another spot. For me, I was trying to drag to add a connection in the middle of a function which didn't work. Dragging to the beginning line of a function or in between functions did work.
Note: I'm on Xcode 9.1
Try selecting your view in the storyboard and clicking on the identity inspector on the right side in class. Enter your view controller name and then drag and drop the item from the storyboard to the view controller.
Hope it helps.
I had to both rename the class (from ViewController to ViewController2) of the ViewController.swift file and change the Custom Class (from ViewController to ViewController2) of the Main Storyboard's View Controller to make Ctrl-Drag-and-drop work again.
Renaming back to ViewController from ViewController 2 in ViewController.swift and Main Storyboard did not thwart the Ctrl-Drag-and-drop, it remained working afterward as well.
Hey I think you are not connected your storyboard viewController with your viewController class. check screen shot which "suhit" uploaded in his answer.
I would like to tell you something more than it.
When ever you need to connect any storyboard object with class.
first go to utility panel (right side) and then set class there.
after that you can connect your controls with class
I hope it will help you.
Check that the names on Viewcontroller identity inspector and the .h, .m files are the same. That worked for me
I'm using Xcode 9.2 I had my ViewControlled refactored into sections using the "extension" keyword. It appears you can't control drag into an extension of a ViewController. If you go up to the top part that is in the class definition, control dragging works fine (assuming you did the other things in this thread about making sure the right class is associated with the view controller.
I had same problem, I realised I selected wrong story board. If you made app with default settings you will get two story boards (Main and Launch Screen). Labels on Launch screen story board cannot drag drop.
Make sure that the item in question is connected to the file in which you want to control drag it to (specify the class in the identity inspector)

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.

Resources