Storyboard uiviewcontroller, 'custom class' not showing in drop down

后端 未结 25 1074
北荒
北荒 2020-12-08 01:34

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

相关标签:
25条回答
  • 2020-12-08 02:08

    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.

    0 讨论(0)
  • 2020-12-08 02:08

    Make sure the view controller is matching with the same Type in the storyboard .

    0 讨论(0)
  • 2020-12-08 02:09

    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.

    0 讨论(0)
  • 2020-12-08 02:10

    I would try the following:

    1. Check that the file implementing the class is part of the build phases (check under target > build phases)
    2. Add the .m file to build phases (if it isn't already).
    3. Restart Xcode.
    0 讨论(0)
  • 2020-12-08 02:10

    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.

    0 讨论(0)
  • 2020-12-08 02:10

    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.

    0 讨论(0)
提交回复
热议问题