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

前端 未结 4 1585
深忆病人
深忆病人 2021-02-19 08:11

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 implem

4条回答
  •  灰色年华
    2021-02-19 08:43

    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.

提交回复
热议问题