customize UIPickerView elements to start at top in xcode?

懵懂的女人 提交于 2019-12-12 04:25:08

问题


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.--> 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];

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) 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];
    }
}


来源:https://stackoverflow.com/questions/13775106/customize-uipickerview-elements-to-start-at-top-in-xcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!