从选择器中选择进行行读取值(Reading value from selected row in p

2019-09-30 07:02发布

我已经建立选择器在Xcode 3列,2。和3.柱填充有基于在第一列中的数据的数据。 它工作正常,并且数据被正确显示,我唯一的问题是我怎么能写ING选择行对2和3列,一些字符串当前显示值?

谢谢。

Answer 1:

使用- [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
}


Answer 2:

实施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];

}


文章来源: Reading value from selected row in picker