gpt4 book ai didi

ios - 连接子类的自定义委托(delegate)以在 Interface Builder 中进行控制

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:21:16 24 4
gpt4 key购买 nike

我有一个带有自定义委托(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

我已经在 Storyboard 中使用自定义子类创建了一个按钮:

有没有办法让自定义委托(delegate)出现在 Storyboard 的可连接属性列表中?

最佳答案

万岁!答案很简单地盯着我的脸。 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

关于ios - 连接子类的自定义委托(delegate)以在 Interface Builder 中进行控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32978577/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com