I am working on an iOS project in Xcode 11 to create an app that converts Farenheit to Celsius. I deleted the default ViewController.swift file and created a custom class with a more descriptive name called ConversionViewController.swift. This file was then saved to the current project. The file contains these lines of code:
class ConversionViewController: UIViewController {
#IBOutlet var celsiusLabel: UILabel!
#IBAction func fahrenheitFieldEditingChanged(_ textField: UITextField) {
celsiusLabel.text = textField.text
}
}
In Main.storyboard I selected the View Controller in the document outline then opened the identity inspector. In the Custom Class section of the identity inspector I changed the class to ConversionViewController and below the module field I checked Inherit module from target. Next, I want to create an outlet to the Celsius text label and create an action for the text field to call when the text changes. So, I open Main.storyboard and try to control-drag from the Conversion View Controller in the document outline to the Celsius label and connect it to the celsiusLabel in ConversionViewController.swift.
The problem is that Xcode won't let me. When I control-drag from the Conversion View Controller to the Celsius label nothing happens. I don't get a pop-up box that gives me the option to select the outlet celsiusLabel.
I've tried going to Product --> Clean Build Folder but that didn't fix the problem. Is there a step missing? I am using the iOS Programming: Big Nerd Ranch Guide 6th edition, which I know isn't written for Xcode 11.
When I control-drag from the Conversion View Controller to the Celsius label nothing happens. I don't get a pop-up box that gives me the option to select the outlet celsiusLabel.
Yes, I often see that problem. Usually I can solve it by dragging a different way. For example, select the label, switch on the right to the Connections inspector, and drag from the circle next to New Referencing Outlet onto the view controller in the outline. Now does it let you make the connection?
In your StoryBoard select the ViewController by clicking on top where the name is displayed after that select the connections inspector (last option). You will see your celsius label there under outlets. Drag from the label's empty circle there to the label in the ViewController's View and connect.
I have faced the same problem:-
It will be resolved by two ways:-
1) After changing the name of the .swift file just clean the build. If it not lets you create outlet then just quit the xcode and run it again then it will allow you to add outlet to the class.
2). In the connections Inspector select the circle coming under Referencing Outlets and drag that to the viewController to create outlet of the control.
This typically happens to me when I move or rename a file. The fix in those circumstances is to remove the file from the 'compile sources' list, then re-add. Then build (no need for clean build).
I'm trying to add an IBOutlet in swift but I only have the option to add an action.
Here is an image of what I'm talking about.
]
Is there any way I can fix this?
I can't change connection type either.
This is happening because you are trying to connect an outlet from the Interface Builder to a non-corresponding View Controller file, so that's why it only gives you the option to add an Exit action. Just make sure that you are in the same View Controller both in the IB and in the Assistant Editor.
P.S. I recommend you renaming properly every view controller so it will be easier to avoid this (make sure to change the name not only in the class but also in the IB). You can use the cmd + click when selecting the class name on the code and click on Rename... to change all at once. If you already changed it in your code, you have also to do it then manually in the IB, selecting the corresponding one from the drop-down menu of the Identity Inspector:
Try ctrl dragging it from the text on the left ()
Restart your Xcode and try to connect #IBOutlet
Simply change the connection type or one more thing you can do. you can do this. By opening connection inspector and drag the outlet into view controller like shown in image..
To Change Connection Type
You should use the same class in your view controller (call it View Controller.swift)
I renamed a class, which happened to have an outlet connection to a label called mainLabel in a storyboard file. When I run my program, it crashes and gives me the error: "this class is not key value coding-compliant for the key mainLabel".
Other SO answers have shown this to be caused by a bad outlet connection, so I removed the connection and removed any lose ends. When trying to reconnect the label to an outlet in my code, I get the error Could not insert new outlet connection: Could not find any information for the class named CourseTableViewCell
Other SO answers have provided solutions which I have tried and haven't worked including:
Deleting the reference to the file and re-adding it
Cleaning the project
Deleting the derived data folder
deleting the label and re-adding it
Dragging from the code to storyboard rather than vice-versa
I made sure that the correct file name was listed in the identity inspector, under "Custom Class". If anybody has any other ideas, please let me know!
I can provide more information if necessary.
The following steps are what you need to do to find existing IBOutlet / IBAction from and object. Be it label, button, etc. And how to remove it.
Open Main.storyboard. The Document outline window should be visible by default on the left of your storyboard window. If not, click the icon on left of the storyboard window, next to the View As: iPhone 7.
Select the object in storyboard, it's easier to find and then select it from the document outline of the storyboard.
Open the Utility window if not yet open on the most right side. Use shortcut key Cmd-Option-0 (command-option-zero), to toggle open/close of the utility window.
Open the connection inspector by click on right arrow icon (top right most icon). Remove any unwanted IBOutlet / IBAction or any other connection you want to remove by clicking on the x icon next to the connection.
Recreate the connection. You could also drag directly from the circle next to the element in the connection window for a particular object. Else add the connection the way you have been doing for now.
As for the Class file and other coding file. You could just comment out the lines that previously have IBAction or IBOutlet. And retype the same line manually (don't cut and paste). Add back the connection from storyboard, and you should be good. Don't forget to delete the lines you commented out that you don't need anymore.
I have a UIViewController I created in my apps storyboard, as well as a custom UIViewController subclass which I added to the project (and is correctly in the compile phase for my target). However when I go to set the 'Custom Class' property on the view-controller in Storyboard my custom class does not show up on the list.
Checked that the class is part of my app's target, not tests'
Double checked that it is correctly a subclass of UIViewController
Compiled program just to make sure xcode was working with latest information
Restarted xcode
What would cause my class to not show up in the 'Custom Class' drop down?
Two ways I found that solve the problem but they are work arounds:-
Just type the view controllers name in the text field, or
close the project and then reopen it and in the project initialization it places the file on the list.
If you still have your problem or for those who could have the same problem:
Make sure to select on your storyboard your "ViewController" instead of your "View" (which is automatically selected when you click on the view in the storyboard). The difference between those two is that when the view controller is selected, a blue rectangle pop up around your app. To be sure to select the view controller, open the document outline and select it directly in your storyboard hierarchy.
I would try the following:
Check that the file implementing the class is part of the build phases (check under target > build phases)
Add the .m file to build phases (if it isn't already).
Restart Xcode.
You can fix this by editing the XML of your Storyboard.
Right-click your My.storyboard entry in the Project Navigator panel and select the Open As->SourceCode menu choice. Find your view controller entry in the XML, and add the attribute customClass="MyController".
Save the storyboard.
Right-click your My.storyboard entry in the Project Navigator panel again, and select the Open As->Interface Builder - Storyboard menu choice.
The custom class entry will now contain your MyController class name.
Make sure your class inherits from UIViewController.
#interface ClassName : UIViewController
In Xcode 8, a few of my classes had the wrong path (case sensitive) specified for their file locations.
MyProject/mysubdirectory/MyViewController.xib (.m, .h)
vs:
MyProject/MySubdirectory/MyViewController.xib (.m, .h)
Really not sure how it ended up in that state, but my project exhibited the exact same behavior as above (no outlets/actions displaying in IB), and fixing that path fixed the problem.
I fixed this two different ways. One way was by I opened the .pbxproj file and fixing the case sensitive issue manually. The other way that worked was by tapping the folder icon under the Identity and Type section of the File Inspector tab of the file, and re-selecting the file there.
Click on a different view controller in the storyboard, then click on it's custom class pulldown to confirm the new class is listed, but don't select it. Click back on the new view controller you made and you should see it now listed in its custom class pulldown menu. odd, eh? just forces a refresh I think.
I had been having the same issues as described in this problem. However, none of the suggested answers fixed it for me. My project compiled OK without warnings or errors, but, in the .h file there were no 'outlet' indicators to indicate that my outlets had been linked to storyboard elements.
Additionally, attempts to create new outlets in my code, by right-click and dragging into my header file, were not recognising my header source as a potential target for this operation. And furthermore, my Class did not make an appearance in the Custom-Class dropdown for the ViewController's property inspector panel.
And yet, the project compiled OK.
Closer examination showed that I had defined my own class in the following manner...
#interface KJBMainDataViewTrackConMk2<UIScrollViewDelegate> : UIViewController
which apparently compiles nicely.
But, if this is changed to the following, (moving the protocols to the end)...
#interface KJBMainDataViewTrackConMk2 : UIViewController<UIScrollViewDelegate>
Then everything springs to life. All outlets are suddenly indicated as being 'connected' with a storyboard element. And right-click dragging starts to work again, and my custom class appears in the custom-class drop-down in the property inspector panel for the storyboard ViewController!
Other answers here probably represent the most likely causes of this condition, but, I felt it worth mentioning at least this one other potential cause.
I had the same problem, but none of the other solutions worked for me. The issue for me was that I had a Mac and iOS target, both with their own versions of the same view controller. For example, I had a .h/.m pair of files named FooViewController for Mac and another .h/.m pair of files named FooViewController for iOS. Each pair was properly included with their respective targets, but for some reason Xcode does not like it and my view controller would not show up in the Custom Class dropdown in the view controller in the storyboard. I ended up renaming my class in the iOS view controller and it immediately showed up in the dropdown.
In my case, I drag a new TableViewController object to the storyboard, but I add a new file which's subclass is "UIViewController".... Then, I add a file which's subclass is "UITableViewController", problem solved!!
For those of you who are still having this problem after trying all the way around is probably because you clicked the View instead of ViewController.
You have to choose the file when ViewController is clicked.
This solved my problem.
I happened to come across this problem, and had no luck after trying the previous suggestions. Finally I found the reason is the header file's type is set to C++ header. After changing it to C header (like all the other header files), the class appears in the drop list. Don't know why though... Possibly helpful for others so I post it here.
Storyboard is looking for the custom class but physically its no there and its not displaying the custom class name in the list and also not displaying the outlets . Following solution perfectly worked for me.
Just copy your code some where else.(Lets say on desktop)
Open your existing code.
Delete the custom class file.(Move to trash)
Now add files from copied project folder (From desktop)
Don't forget to check "Copy if needed" check box
Open the story board and bingo you will get your custom class files in dropdown
be sure initially not adding the CustomViewController to any group or folder. place it in the root of your app.
none of the above(or below :) helped me. though I found that
after adding new viewcontroller to storyboard (just by dragging it in)
and adding my class by File\New\File\Objective-C Class, give it a name, no XIB, Next, Create
if I select my viewcontroller in storyboard and try to assign my class to it - my class is not there
BUT
if I click on a view that is in the viewcontroller itself then click on a class dropdown menu in Custom Class
AND THEN
select viewcontroller (click on a bar below the viewcontroller) and now again click on a class dropdown in Custom Class my newly added class magically shows up.
weird, must be a bug with refreshing. Xcode Version 5.1 (5B130a)
Make sure you select View Controller to which you want to attach your class. The easy way is open Document Outline and choose your view controller (When you tap on it form the Storyboard sometimes it simply doesn't choose the object you meant).
for my case, somehow bundle resources got deleted, so I added back and worked!
Build Phases -> Add Build Phase -> Copy Bundle Resources
find your file
Then drag and drop your file there
Then make sure your target membership is checked.
In my case, I selected the wrong UI.. so I deleted the class file and created a new one and selected the correct parent class
I had to restart XCode 7.3 (7D175)
What worked for me was, click on the file in the Project Navigator, then, in the File Inspector under "Identity and Type" beneath the "Location" dropdown box, click on the little folder icon and then select the file in the popup window.
Try to clean your project, and also restart your Mac. One peculiar thing that I did was change all the Custom Classes names and build the project again. It worked!
For macOS projects, creating a new class generated a class inheriting from NSObject instead on NSViewController.
Change from
import Cocoa
class AppsViewController: NSObject {
}
to
import Cocoa
class AppsViewController: NSViewController {
}
I was fairly frustrated with this issue as none of the answers above had solved my problem.
In my case: I was in the middle of working on swift view controller file and was making active changes (such as creating a custom collection cell class). I had not finished the code block and left it open like so :
class tableViewCell: UITableViewCell {
}
class collectionCell:
class viewController: UIViewController {
override func viewDidLoad(){
super.viewDidload()
}
}
Note the incomplete code block 'collectionCell2'
This was enough for xcode to not recognize my viewController file as such.
Once I completed this block the file reappeared in my xcode as an option.
Very silly and simple.
Make sure the view controller is matching with the same Type in the storyboard .
In my case swift file name was different then swift class name i.e
file name was ViewControllerTest.swift
and class name was ViewController.swift
after changing both to common name solved my problem
Restart Xcode after above changes
Make sure the class name of the ViewController is the name that you want. i.e.
class MyCustomNameViewController: UIViewController {
.
.
}
Changing just the filename is not enough.