问题
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.
回答1:
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
. TheDocument 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 theView As: iPhone 7
. - Select the object in
storyboard
, it's easier to find and then select it from thedocument outline
of thestoryboard
. - Open the
Utility window
if not yet open on the most right side. Use shortcut keyCmd-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 thex
icon next to the connection. - Recreate the connection. You could also drag directly from the
circle
next to theelement
in theconnection window
for a particularobject
. 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.
来源:https://stackoverflow.com/questions/38256039/renaming-class-causes-iboutlet-connection-to-fail