简体   繁体   English

在Interface Builder中连接子类的自定义委托以进行控制

[英]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: 我在自定义子类的Storyboard中创建了一个按钮:

Is there a way to get the custom delegate to appear in the list of connectable properties in the Storyboard? 有没有办法让自定义委托出现在Storyboard的可连接属性列表中?

Huzzah! 好哇! The answer was quite simply staring me in the face. 答案很简单地盯着我。 The delegate (or dataSource ) definitions need to include IBOutlet : 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以在界面构建器中连接CustomViews的delegate和dataSource? - Is it possible to connect delegate and dataSource of CustomViews in interface builder? 没有接口生成器的自定义 UITabBar 子类 - Custom UITabBar subclass without Interface Builder 在Interface Builder中呈现自定义UITextField子类的错误 - Errors with rendering custom UITextField subclass in Interface Builder iPhone Interface Builder 中的自定义控件 - Custom Control in iPhone Interface Builder UITextView的接口构建器和子类 - Interface builder and subclass of UITextView 在Interface Builder上,将UILabel连接到自定义UIView IBOutlet - On Interface Builder connect UILabel to custom UIView IBOutlet 如何在XIB(接口构建器)中使用UIPageViewController的子类来设置DataSource,Delegate和TransitionStyle - How to use Subclass of UIPageViewController in XIB (Interface Builder) to set DataSource, Delegate and TransitionStyle UIView子类:检测在接口构建器中设置的UIView的大小,该生成器使用所述UIView子类作为自定义类 - UIView Subclass: Detect the size of a UIView set up in Interface Builder which uses said UIView subclass as a custom class 将UINavigaitionController连接到“接口”构建器中的委托 - connecting UINavigaitionController to the delegate in Interface builder 在界面构建器中更改SearchDisplayController委托 - Changing SearchDisplayController Delegate in interface builder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM