UIPickerView 中的 UIButton 不响应单击事件
我通过此代码将 UIButton 添加到 UIPicker 视图,
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
UIView *returnedView=(id)view;
if (!returnedView) {
returnedView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, [pickerView rowSizeForComponent:component].width, 44)];
}
returnedView.userInteractionEnabled=YES;
UILabel *retval=[[[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f,50, 44)] autorelease];
retval.text = [[_figureArrayPicker objectAtIndex:row] valueForKey:@"FIGPic"];
UIButton *button=[self pieChartOfFigureWithCmm:row];
[button setFrame:CGRectMake(50, 0, 50, 44)];
[button addTarget:self action:@selector(defectPressed:)
forControlEvents:UIControlEventTouchUpInside];
[returnedView addSubview:button];
}
[returnedView addSubview:retval];
return returnedView;
}
但是当我单击 uibutton 时,它没有响应。 我的错误在哪里? 谢谢。
i add an UIButton to an UIPicker view bu this code
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
UIView *returnedView=(id)view;
if (!returnedView) {
returnedView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, [pickerView rowSizeForComponent:component].width, 44)];
}
returnedView.userInteractionEnabled=YES;
UILabel *retval=[[[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f,50, 44)] autorelease];
retval.text = [[_figureArrayPicker objectAtIndex:row] valueForKey:@"FIGPic"];
UIButton *button=[self pieChartOfFigureWithCmm:row];
[button setFrame:CGRectMake(50, 0, 50, 44)];
[button addTarget:self action:@selector(defectPressed:)
forControlEvents:UIControlEventTouchUpInside];
[returnedView addSubview:button];
}
[returnedView addSubview:retval];
return returnedView;
}
but when i click on an uibutton this doesn't respond.
where was my mistake?
Thks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需尝试显式更改按钮的 userInteractionEnabled=YES ,也许这就是这里的情况。
Just try explicitly changes userInteractionEnabled=YES for button also, may that can be a case here.
为您的按钮分配内存。
Allocate memory to your button.