简体   繁体   English

我怎样才能使pickerview的标题文本化

[英]how can i get the title of pickerview to textfied

i am writing an application in which when we click on a textfield it generates a pickerview. 我正在编写一个应用程序,当我们单击文本字段时,它会生成一个pickerview。 pickerview has two components pickerview有两个组成部分

now what is my question is i want to get the titles of both the components which are highlighted into my textfield separated by a comma(,) 现在我的问题是我想获取突出显示在我的文本字段中的两个组件的标题,并用逗号(,)分隔

thanks in advance. 提前致谢。

Lets says you have a UIPickerView object called as pickerView. 假设您有一个名为PickerView的UIPickerView对象。 When the user completes his action and taps the done button, you should get the selected value as 当用户完成其操作并点击完成按钮时,您应该将选定的值作为

int offset1 = [pickerView selectedRowInComponent:0];
int offset2 = [pickerView selectedRowInComponent:1];

NSString *str = [NSString stringWithFormat:@"%@,%@",[arrOne objectAtIndex:offset1],[arrTwo objectAtIndex:offset2]];

Where arrOne and arrTwo are the array's used to populate the pickerview. 其中arrOne和arrTwo是用于填充pickerview的数组。

If you have set the pickerview delegates then write this snippet under 如果您已经设置了pickerview代表,则将该代码段写在

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    for(NSUInteger k = 0; k < <number of components>s; ++k++)
    {
        NSUInteger selectedRow = [<Your pickerview name> selectedRowInComponent:k];
        NSString *title = [[<Your pickerview name> delegate] pickerView:<Your pickerview name> titleForRow:selectedRow inComponent:i];
       [<Your temporary string> appendFormat:@"Selected item \"%@\" in component %lu\n", title, i];
    }
}

if you add UIPickerViewDataSource,UIPickerViewDelegate Delegate then in delegate method you can directly assign this value like bellow... 如果添加UIPickerViewDataSource,UIPickerViewDelegate Delegate,则在委托方法中,您可以像下面这样直接分配此值...

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    yourTextField.text = [NSString stringWithFormat:@"%@,%@",[arr1 objectAtIndex:row],[arr2 objectAtIndex:row]];

}

hope this help you... 希望这对您有帮助...

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

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