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 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.
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).
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.
be sure initially not adding the CustomViewController to any group or folder. place it in the root of your app.
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 {
}