从选择器中的选定行读取值

我已经在Xcode中创建了带有3列的选择器,2和3列根据第一列中的数据填充了数据。 它运行正常,数据显示正确,我唯一的问题是我如何编写当前显示2.和3.列选定行的值到某些字符串?

谢谢。

使用 – [UIPickerView selectedRowInComponent:]确定选择了哪一行,然后返回数据数组中该索引处的对象。

  - (void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row inComponent:(NSInteger)component { NSInteger selectedRow = [pickerView selectedRowInComponent:0]; NSString *selectedPickerRow=[yourArrayOfElements objectAtIndex:selectedRow]; // Handle the selection } 

实现didSelectRow委托

 - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:0]; UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; NSString *cellText = [NSString stringWithString: cell.textLabel.text]; NSIndexPath *indexPath1 = [NSIndexPath indexPathForRow:row+1 inSection:0]; UITableViewCell *cell1 = [self.tableView cellForRowAtIndexPath:indexPath1]; NSString *cell1Text = [NSString stringWithString: cell1.textLabel.text]; NSIndexPath *indexPath2 = [NSIndexPath indexPathForRow:row+2 inSection:indexPath.section]; UITableViewCell *cell2 = [self.tableView cellForRowAtIndexPath:indexPath2]; NSString *cell2Text = [NSString stringWithString: cell2.textLabel.text]; }