IOS - control-drag of a button is not working - ios

I have some buttons I am trying to create, and when I try to do a control-drag into the controller, it isn't showing me the options to create configure that button. Any idea what could be wrong? I am just following my first tutorial is its probably something for newbies.
My screen shot is attached.

It seems that you opened an incorrect .h file in your assistant editor, you will need to open the correct interface file for the correct view controller you have in your nib
from what i can see is that LearningCenter should not be the interface opened,
You will need to change the assistant view controller to the correct one
Check the screen shot

just right click on your button from that select last option (New Referencing outlet collections. from that map your .h file . At the time a popup will appear. just enter your button name.

Related

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)

Cannot use CTRL+Drag for making a button action in Xcode?

Somethings I have a navigation controller and a view controller in my Main.Storyboard, but for some reason I can't create and link IBActions by holding down CTRL and clicking on a button on my view controller, then dragging it to my ViewController.swift. I could do this earlier!? What happened? Thanks
Solved! I'm using a program that allows my mouse and keyboard to work between my Mac and PC without taking it out of the USB ports (works over LAN). For some reason the program is not recognizing a CTRL press which was causing the problem. After switch the keyboard to the mac itself, everything works!
this happened to me before : click on the view controller and then go to utilities -> identity inspector , and check the "Class"
The class has to be the same as the file you're trying to ctrl drag into
here is the picture: https://www.dropbox.com/s/5451kzit16espjo/Screen%20Shot%202015-07-08%20at%2010.50.45%20AM.png?dl=0
Open your xib file or storyBoard
Click on File’s Owner
Click on Identity Inspector and check class has same name as the file you’re trying to ctrl drag
This guy have awesome solution. Just need to correct your class name
ios – can’t drag and drop item by ctrl+drag xcode

How to link a button to an action in Xcode 6?

I am trying to create a button, that when it receives the "Touch Up Inside" call, will ring a phone number. However, the action I have declared in my ViewController.h is not showing up in my Connections Inspector, so I cannot connect the code to my button. Within my ViewController.h I have written the line of code:
-(IBAction)makePhoneCall(id)sender;
And I have finished my declaration in my ViewController.m, but it still wont appear in my Connections Inspector.
Any suggestions for help would be greatly appreciated.
What you need is to go to your storyboard, click on the Utilities button on the far right.
From there click on your controller; third tab from left you will see "Custom Class", there you need to change the name to the name of the class in which you declare your method.
See picture:
From then on, try to connect your method again using connection inspector.
Edit:
Adding picture for selecting the view controller in storyboard:

xcode: Problems connecting main storyboard

I am following the tutorial here. I just created my first storyboard and tried to set it as the main storyboard. After following the tutorial I clicked the run button and the simulator doesn't render any of the changes ive created.
I have a screen shot of my xcode project here(not sure how else to display it): https://app.box.com/s/okw7jlzq5zmcetd5cehu
What am I doing wrong?
Here is another screenshot of the storyboard itself: https://app.box.com/s/jt6i0an3maowwvgsamk7
Place a checkmark in the box "Is Initial View Controller" for the view controller you want to load.
I think your problem is the code in the app delegate. When you use a storyboard, you don't need anything in there except "return YES". The storyboard creates the window, so the code you have in there is making another window, not the one that your storyboard controller is a subview of.
Using this tutorial might teach you some things about the structure of an iOS app, but if you just want to make an app with a storyboard, you should start with the "single view" template instead of the "empty" one. It will give you a storyboard and an initial controller.

"loaded nib but the view outlet was not set" exception

I am trying to use UINavigationController. I have two views which are being created programmatically. When a UIButton is pressed on the first view, the second view should come to foreground.
But here application crash with exception:
loaded nib but the view outlet was not set
What can be cause of this and how to resolve it.
follo following steps
1) open your xib file then right click on files owner and drag to your first view
2) then bind that view with outlet of "view"
hope you will get it...
Do This(You have no view in xib so add one and then do this):
Open the XIB file causing problems
Click on file's owner icon on the left bar (top one, looks like a yellow outlined box)
If you don't see the right-hand sidebar, click on the third icon above "view" in your toolbar. This will show the right-hand sidebar
In the right-hand sidebar, click on the third tab--the one that looks a bit like a newspaper
Under "Custom Class" at the top, make sure Class is the name of the ViewController that should correspond to this view. If not, enter it
In the right-hand sidebar, click on the last tab--the one that looks like a circle with an arrow in it
You should see "outlets" with "view" under it. Drag the circle next to it over to the "view" icon on the left bar (bottom one, looks like a white square with a thick gray outline
Save the xib and re-run
Thanks,
If you are not seeing the "view" outlet to select from on the "Connections inspector" (rightmost) tab, I found that I had to go back to a generic view controller (e.g., UICollectionViewController) for the File's Owner Custom Class instead of my subclass that I had entered previously. After closing and reopening Xcode, the view outlet appeared again so I connected it as described in sagarcool89's answer. I then set my File's Owner Custom Class back to my subclass and have finally moved past this error.
Select File's owner of your .xib, open the Identity Inspector, make sure Custom Class is set to the same name as your controller's class name. If you create IB file and Controller separately(in separate steps), you might forget to check this.
If you have tried everything and you still get this error, try re-creating the class file from scratch but remember to select the "Also create XIB file" check box. This will auto link up a few items that are not linked when creating these files separately. After this is created, you can likely cut and paste everything onto the new XIB and it should work fine.

Resources