在Interface Builder

时间:2015-10-06 19:56:54

标签: ios objective-c delegates storyboard

我有一个自定义控件和自定义委托:

@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

我在Storyboard中创建了一个带有自定义子类的按钮:

有没有办法让自定义委托出现在故事​​板中的可连接属性列表中?

1 个答案:

答案 0 :(得分:5)

好哇!答案很简单地盯着我。 delegate(或dataSource)定义需要包含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