简体   繁体   English

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

[英]Reading value from selected row in picker

i have created picker in Xcode with 3 columns, 2. and 3. column are filled with data based on the data in first column. 我已经在Xcode中用3列,2。和3.创建了选择器,并根据第一列中的数据填充了数据。 It works fine, and data is displaying correctly, my only problem is how can i write value that is currently displaying ing selected row for 2. and 3. column to some string? 它工作正常,数据正确显示,我唯一的问题是如何将当前显示的2和3列的所选值写入某个字符串?

Thank you. 谢谢。

Use - [UIPickerView selectedRowInComponent:] to determine which row is selected, and then return the object at that index within your data array. 使用- [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
}

Implement didSelectRow delegate 实现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];

}

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

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