简体   繁体   English

在其他View Controller的标签上显示UIPicker选择

[英]Display UIPicker selection on a label in other View Controller

Working on an App for Ipad which has one main view controller and 3 popover views, each popover view has a UIPicker, I want to display in 3 different labels located in the main view controller the UIPickers selection, each label is asociated to its own UIPicker. 在具有一个主视图控制器和3个弹出视图的Ipad应用程序上工作,每个弹出视图都有一个UIPicker,我想在主视图控制器中的3个不同标签中显示UIPickers选择,每个标签都与自己的UIPicker相关联。 I had been trying with delegate objects to pass the data from the pickers to the labels but something is wrong. 我一直在尝试使用委托对象将数据从选择器传递到标签,但是出了点问题。 Any clue PLEASE! 有任何线索请! Thanks. 谢谢。

The easiest way is to use tags. 最简单的方法是使用标签。

typedef enum { 
  FirstPicker = 1,
  SecondPicker,
  ThirdPicker 
} PickerTags; 

When you create the picker, indicate which one it is by setting the tag either in storyboard or like this 创建选择器时,通过在情节提要中设置标记或类似标记来指示是哪个选择器

picker.tag = FirstPicker; 

In your picker callbacks it is now easy to identify the picker: 在选择器回调中,现在可以轻松识别选择器:

- (void)pickerView:(UIPickerView *)pickerView 
      didSelectRow:(NSInteger)row 
       inComponent:(NSInteger)component {

   if (picker.tag == FirstPicker) { /* handle first picker */ }
   // etc.
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM