gpt4 book ai didi

iphone - 设置委托(delegate)时崩溃

转载 作者:行者123 更新时间:2023-12-01 19:08:02 25 4
gpt4 key购买 nike

我有一个带有 nib 和协议(protocol)的自定义 View (设置 View )。我想将此 View 添加到带有委托(delegate)的 View Controller 上。当我设置它的委托(delegate)时,我的应用程序崩溃了,我不知道我做错了什么。

我没有用于 ViewController 的 NIB。

我附上了我的代码和 View 的 NIB 的几张图片。

-[UIView setDelegate:]: unrecognized selector sent to instance 0xb265e20

。H

@protocol  SettingViewDelegate

@required

-(void)CornerSlider:(id)sender;
-(void)MarginSlider:(id)sender;
-(void)BorderSlider:(id)sender;
-(void)ShadowSlider:(id)sender;
-(void)BorderColor:(id)sender;
-(void)ShadowColor:(id)sender;
-(void)remove:(id)sender;
@end

@interface SettingView : UIView

@property (nonatomic, assign) id delegate;

-(IBAction)CornerSlider1:(id)sender;
-(IBAction)MarginSlider1:(id)sender;
-(IBAction)BorderSlider1:(id)sender;
-(IBAction)ShadowSlider1:(id)sender;
-(IBAction)BorderColor1:(id)sender;
-(IBAction)ShadowColor1:(id)sender;
-(IBAction)remove1:(id)sender;

@end

.m
@implementation SettingView


- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self = [[[NSBundle mainBundle] loadNibNamed: @"Setting"
owner: self
options: nil] objectAtIndex:0];
}
return self;
}

-(IBAction)CornerSlider1:(id)sender
{
[self.delegate CornerSlider:sender];
}
-(IBAction)MarginSlider1:(id)sender
{
[self.delegate MarginSlider:sender];
}
-(IBAction)BorderSlider1:(id)sender
{
[self.delegate BorderSlider:sender];
}
-(IBAction)ShadowSlider1:(id)sender
{
[self.delegate ShadowSlider:sender];
}
-(IBAction)BorderColor1:(id)sender{
[self.delegate BorderColor:sender];
}
-(IBAction)ShadowColor1:(id)sender{
[self.delegate ShadowColor:sender];
}
-(IBAction)remove1:(id)sender{
[self.delegate remove:sender];
}


@end

Views Nib

设置委托(delegate)后,应用程序在此处崩溃。
SettingView *settingView=[[SettingView alloc]init];
[settingView setDelegate:self];
[self.view addSubview:settingView];

最佳答案

将@required 替换为@optional

@protocol  SettingViewDelegate

@optional

-(void)CornerSlider:(id)sender;
-(void)MarginSlider:(id)sender;
-(void)BorderSlider:(id)sender;
-(void)ShadowSlider:(id)sender;
-(void)BorderColor:(id)sender;
-(void)ShadowColor:(id)sender;
-(void)remove:(id)sender;
@end

关于iphone - 设置委托(delegate)时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18587318/

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