我正在写一个应用程序,当我们点击一个文本字段时,它会生成一个选择器视图。选取器视图有两个组件
现在我的问题是,我想获得两个组件的标题,这两个组件在文本字段中突出显示,用逗号(,)分隔
提前谢谢。
发布于 2012-12-18 17:37:33
假设您有一个名为pickerView的UIPickerView对象。当用户完成他的操作并点击done按钮时,您应该会得到如下所选值
int offset1 = [pickerView selectedRowInComponent:0];
int offset2 = [pickerView selectedRowInComponent:1];
NSString *str = [NSString stringWithFormat:@"%@,%@",[arrOne objectAtIndex:offset1],[arrTwo objectAtIndex:offset2]];其中arrOne和arrTwo是用于填充选择器视图的数组。
发布于 2012-12-18 17:35:13
如果您设置了选择器视图委托,则将此代码段写在
- (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];
}
}发布于 2012-12-18 17:49:40
如果你添加了UIPickerViewDataSource,UIPickerViewDelegate委托,那么在委托方法中,你可以像下面这样直接赋值。
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
yourTextField.text = [NSString stringWithFormat:@"%@,%@",[arr1 objectAtIndex:row],[arr2 objectAtIndex:row]];
}希望这能帮到你。
https://stackoverflow.com/questions/13929819
复制相似问题