我有一个带有 nib 和协议的自定义视图(设置视图)。我想将此视图添加到带有委托的视图控制器上。当我设置它的委托时,我的应用程序崩溃了,我不知道我做错了什么。
我没有用于 ViewController 的 NIB。
我附上了我的代码和 View 的 NIB 的几张图片。
。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
设置委托后,应用程序在此处崩溃。
SettingView *settingView=[[SettingView alloc]init];
[settingView setDelegate:self];
[self.view addSubview:settingView];