如何判断哪个控件被触摸了?

发布于 2024-10-01 04:24:03 字数 118 浏览 2 评论 0原文

我的视图中有两个 PickerView,如何设置我的委托来识别要处理哪一个? 某种 if() 来验证引发事件的选择器是 pickerX 还是 pickerY?

任何想法将不胜感激。

I have two PickerViews in my view, how do I set my delegates to identify which one to handle?
Some kind of if() to validate if the picker that threw the event was the pickerX or pickerY?

Any ideas will be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

来世叙缘 2024-10-08 04:24:03

您可以为 PickerViews 使用 IBOUtlet

@property (nonatomic, retain) IBOutlet UIPickerView *firstPickerView; 
@property (nonatomic, retain) IBOutlet UIPickerView *secondPickerView; 

,然后在委托方法中执行类似的操作

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:  (NSInteger)component {
  if (pickerView == self.firstPickerView) {
  }
  else if (pickerView == self.secondPickerView) {
  }
}

,或者您可以在 IB 中的 PickerViews 上设置标签并执行

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:  (NSInteger)component {
  if (pickerView.tag == 0) {

  }
  else if (pickerView.tag == 1) {
  }
}

You can have IBOUtlets for the PickerViews like

@property (nonatomic, retain) IBOutlet UIPickerView *firstPickerView; 
@property (nonatomic, retain) IBOutlet UIPickerView *secondPickerView; 

and then in a delegate method do something like this

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:  (NSInteger)component {
  if (pickerView == self.firstPickerView) {
  }
  else if (pickerView == self.secondPickerView) {
  }
}

or you can set tags on the PickerViews in IB and do

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:  (NSInteger)component {
  if (pickerView.tag == 0) {

  }
  else if (pickerView.tag == 1) {
  }
}
星星的轨迹 2024-10-08 04:24:03

当调用任何委托方法时,它还会传递调用它的对象,在本例中可以这样说。

– pickerView:rowHeightForComponent:

您可以通过其 TAG id 来识别特定选择器。是的,如果会使用 else 的话。

When any delegate method is called, it also pass the object on which it is called, lets say in this case.

– pickerView:rowHeightForComponent:

You can identify the particular picker by its TAG id. And yah if else will be used.

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