How to link ibOutlet from subview to custom UIView Class in storyboard xcode
Asked Answered
F

4

14

I think this image explains it all. I have a subclass of UIView that I've entered into the class field. I'm trying to connect ibOutlets between the storyboard and class implementation. It's not giving me an error, but it's not working either. Is this another xcode bug, or am I expecting this to work in a way that it won't?

enter image description here

Festal answered 20/1, 2015 at 18:47 Comment(0)
A
14

Here is a solution:

1) Type an IBOutlet by hands in your header file, example:

@property (strong, nonatomic) IBOutlet ProgressBarElementView *targetProgressElement;

2) Drag the pin from the code to the element in document outline zone

enter image description here

Annettannetta answered 4/10, 2015 at 22:52 Comment(1)
Make sure the view has been set as the custom class otherwise this won't work.Allergen
A
0

I have the same problem.. I saw that if you add the custom class to the root view in the view controller, it will work.. In your case this is the initial View, listed under Bottom Layout Guide

But there must be a better way

Accommodating answered 26/3, 2015 at 14:21 Comment(0)
F
0

To overcome XCode stubborness, especially when you need to hook up different enums from UIControlEvent than UIControlEventTouchUpInside, I'd rather use code directly from within the custom view class:

SWIFT

button.addTarget(self, action:#selector(ClassName.handleRegister(sender:)),
                          for: .touchDragExit)

OBJECTIVE-C

[self.button addTarget:self
                action: @selector(buttonTouchDragExitAction:)
      forControlEvents:UIControlEventTouchDragExit];

One might include such code in awakeFromNib or viewDidLoad or where it best suits.

Floater answered 29/4, 2017 at 9:13 Comment(0)
A
0

write the outlet inside your custom UIView

    @IBOutlet weak var imageView: UIImageView! 

then drag it into the storyboard on the view

Amain answered 15/4, 2020 at 13:4 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.