NSInvalidArgumentException', reason: ***unrecognized selector sent to instance
问题
-(void)creatEffectSet:(NSInteger)tag framebutton:(CGRect)framebutton{
CustomUISwitch *customSwitch = [[CustomUISwitch alloc] initWithFrame:framebutton];
customSwitch.tag = tag;
[customSwitch addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:customSwitch];
[customSwitch release];
}
原因是customSwitch变量声明成局部变量,action无法识别
customSwitch声明成该类的全局变量
在头文件中定义CustomUISwitch *customSwitch;
问题
-(void)creatEffectSet:(NSInteger)tag framebutton:(CGRect)framebutton{
CustomUISwitch *customSwitch = [[CustomUISwitch alloc] initWithFrame:framebutton];
customSwitch.tag = tag;
[customSwitch addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:customSwitch];
[customSwitch release];
}
原因是customSwitch变量声明成局部变量,action无法识别
customSwitch声明成该类的全局变量
在头文件中定义CustomUISwitch *customSwitch;