我想做个多选功能,在viewforrow方法里放入了一个uibuuton,并addtarget了方法,但是点击这一行的时候,uibutton的点击事件不起作用,这是什么原因?求大神指教
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UIButton *s = [[UIButton alloc] init];
[s setBackgroundColor:[UIColor grayColor]];
[s setTitle:@"ddd" forState:UIControlStateNormal];
[s addTarget:self.pickerDictionary action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
return s;
}- (void)buttonClick //不起作用
{
NSLog(@"111");
}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UIButton *s = [[UIButton alloc] init];
[s setBackgroundColor:[UIColor grayColor]];
[s setTitle:@"ddd" forState:UIControlStateNormal];
[s addTarget:self.pickerDictionary action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
return s;
}- (void)buttonClick //不起作用
{
NSLog(@"111");
}
改成
[s addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
试试因为你的buttonClick事件是在当前类中实现的,不是写在self.pickerDictionary中