Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect subclass's custom delegate for control in Interface Builder

I've got a custom control with a custom delegate:

@class MyButtonSubclass;
@protocol MyButtonSubclass Delegate <NSObject>
@optional
- (void)delegateMethod:(NSString *)param;

@end

@interface MyButtonSubclass : UIButton

@property (nonatomic, weak) id < MyButtonSubclass Delegate> delegate;
@property (nonatomic, strong) NSString* param;

@end

And I've created a button in a Storyboard with the custom subclass:

Is there a way to get the custom delegate to appear in the list of connectable properties in the Storyboard?

like image 510
brandonscript Avatar asked Jan 17 '26 03:01

brandonscript


1 Answers

Huzzah! The answer was quite simply staring me in the face. The delegate (or dataSource) definitions need to include IBOutlet:

@class MyButtonSubclass;
@protocol MyButtonSubclass Delegate <NSObject>
@optional
- (void)delegateMethod:(NSString *)param;

@end

@interface MyButtonSubclass : UIButton

@property (nonatomic, weak) IBOutlet id < MyButtonSubclass Delegate> delegate;
//                              ^ This!       
@property (nonatomic, strong) NSString* param;

@end
like image 76
brandonscript Avatar answered Jan 19 '26 17:01

brandonscript



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!