I am able to right-click and drag from my custom UIView subclass file to the storyboard elements to connect them, but unable to do so the other way around. I believe this is
1: Assign the class to viewController.
2: Clean your project with Shift-Alt-Cmd-K.
3: First quit Xcode and clear the derived data. going to: ~/Library/Developer/Xcode/DerivedData
After trying some of the given solution what finally worked is by restarting the my macbook. It seems like a bug on XCode's side. Oh well.
press ctrl than drag to swift file and create outlet.
Things to check if IBOutlet
does not connect:
Is the class defined in storyboard?
Select the UIViewController
in storyboard
, then on the right side of the screen, select the identity inspector
and assign the appropriate class.
Are the type of outlet you defined match the one on storyboard
?
For example, we connect UIButton
, then the outlet should look like that, write the code for the outlet, then connect to the view controller:
@IBOutlet weak var theButton: UIButton!
Create an outlet like this in Objective-C
@property (nonatomic, weak) IBOutlet UIView *view;
or as in swift 3
@IBOutlet weak var instruction: UILabel?
and then connect it as given in this image.
Sometimes the normal way of connecting action and outlet doesn't work due to subclassing. This way comes handy for such situations.
Another way just create your button name manually in view controller like this -
@IBOutlet weak var button: UIButton!
then connect your button via drag to view controller as image shown [!
PS:- please clean your derived data also.