通过表格单元格更改选择器视图数据

时间:2012-06-26 03:40:44

标签: iphone uitableview uipickerview

我有一个UITableView,包含3个UITableViewCells和3个Picker Views以及其他数据。

Picker1有Data1

Picker2有Data2

Picker3有Data3

这与代码:

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row      forComponent:(NSInteger)component;
{
if (thePickerView.tag == 1) {
    return [data1 objectAtIndex:row];
} else if (thePickerView.tag == 2) {

return [data2 objectAtIndex:row];        

} else if (thePickerView.tag == 3) {

    return [data3 objectAtIndex:row];

}
return [data1 objectAtIndex:row];

}

我想用UITableViewCell更改选择器视图的数据。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

这样做会在.h文件中创建memberVariable NSIndexPath * selectedIndexPath 并创建其属性。

现在在tableViewDelegate方法中:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    selectedIndexPath = [indexPath retain];
    //reload pickerview here
}

Picker View Delegate方法将如下所示:

- (NSString *)pickerView:(UIPickerView *)pickerView 
          titleForRow:(NSInteger)row forComponent:(NSInteger)component 
{
  switch (selectedIndexPath.row) 
  {
    case 0:
        //first cell selected picker view
        break;
    case 1:
        //second cell selected picker view
        break;
    case 2:
        //third cell selected picker view
        break;
     default:
     break;
  }
}