UIPickerView 中的 UIButton 不响应单击事件

发布于 2024-12-09 09:34:17 字数 988 浏览 1 评论 0原文

我通过此代码将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南冥有猫 2024-12-16 09:34:17

只需尝试显式更改按钮的 userInteractionEnabled=YES ,也许这就是这里的情况。

Just try explicitly changes userInteractionEnabled=YES for button also, may that can be a case here.

恬淡成诗 2024-12-16 09:34:17

为您的按钮分配内存。

Allocate memory to your button.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文