自定义UIPickerView元素以从xcode的顶部开始? [英] customize UIPickerView elements to start at top in xcode?

查看:49
本文介绍了自定义UIPickerView元素以从xcode的顶部开始?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1 .-->我需要自定义一个UIPickerview元素以从顶部开始,到现在为止我们可以看到选择器元素从中间开始,如图所示(苹果从选择器中间开始),但是没有从一开始...有办法吗?我该怎么办?

1.--> I need to customize a UIPickerview elements to start from the top.As of now we can see the picker elements starting from the middle like the one shown in figure(apple started from middle of picker) but not from the top... Is there a way to do it?How can I do it ?

2 .-->首次显示时如何使PickerView从某行开始我知道这段代码:

2.--> How can I make a PickerView Start At A Certain Row When It Is First Displayed I knew this code:

  [self.view addSubview:aPicker];
  [aPicker selectRow:14 inComponent:0 animated:NO];

但是我有一个文本字段,并且我想要文本字段文本(例如:California),它也是pickerView的元素之一,但是不知道其行位置显示为UIPickerView的默认值.做到了吗?

But I have a textfield and I want the textfield text (eg: California) which is also one of the element of pickerView ,but its row position is not known to be displayed as the default value of UIPickerView..How can I do it ?

推荐答案

1)不确定您的意思.您是否希望选择指示器位于顶部,并且使选择器在旋转时停在该位置?如果是这样,我认为这将是一件困难的事情.

1) Not sure what you mean here. Do you want the selection indicator to be at the top, and for that to be where the picker stops when you spin it? If so, I think that would be a hard thing to do.

2)要使选择器从特定行开始,只需获取数据源数组中该项目的索引,然后根据该选择器选择行.像这样的东西可以用作文本字段的操作方法:

2) To have the picker start at a particular row, just get the index of that item in the data source array, and select the picker row based on that. Something like this could be used as the text field's action method:

-(IBAction)startPickerAtText:(UITextField *) sender {
    NSInteger indx = [self.theData indexOfObjectIdenticalTo:sender.text];
    if (indx != NSNotFound) {
        [self.picker selectRow:indx inComponent:0 animated:YES];
    }
}

这篇关于自定义UIPickerView元素以从xcode的顶部开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆