使用segue iOS将数据从一个表视图单元格传递到另一个表格单元格

时间:2013-11-27 10:49:28

标签: ios objective-c ipad storyboard segue

我有一个包含行X,Y,Z的表视图。我想要的是当用户选择X时它应该显示另一个包含行X1,X2,X3的子表视图;当用户选择Y时,它应该加载另一个子行表视图,行Z1,Y2,Y3等。 这就是我正在做的事情:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
arrOEMs = [[NSMutableArray alloc]init];
OEMs = [NSArray arrayWithObjects:@"X",@"Y",@"Z", nil];
//NSDictionary *oemDict = [NSDictionary dictionaryWithObject:OEMs forKey:@"OEMs"];
//[arrOEMs addObject:oemDict];
childrenof1stOEM = [NSArray arrayWithObjects:@"X1",@"X2",@"X3", nil];
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath     *)indexPath
{
if (indexPath.row == 0) 
{
    NSLog(@"1st selected");
   //show X1,X2,X3 in another table view
   passIndexPath = indexPath;
   //NSDictionary *dictinary = [arrOEMs objectAtIndex:indexPath.section];
   //NSArray *array = [dictinary objectForKey:@"OEMs"];
   //selectedOEMs = [array objectAtIndex:indexPath.row];
   [self performSegueWithIdentifier:@"OEMDetailsConnectorSegue" sender:self];
}
if (indexPath.row == 1) {
    NSLog(@"2 selected");
  //Show Y1,Y2,Y3 in another table view
}
if (indexPath.row == 2) {
    NSLog(@"3 selected");
}

调用segue如下:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"OEMDetailsConnectorSegue"])
{
     //NSLog(@"2 selected");

   OEMsDetailViewController *destViewController = segue.destinationViewController;
    //destViewController.OemNames = self.selectedOEMs; //showing exception at this step
    //destViewController.parentIndex = passIndexPath;
    if (passIndexPath.row == 0) {
       destViewController.childData = [childrenof1stOEM objectAtIndex:passIndexPath.row];
    }
}
}

" childrenof1stOEM"没有被分配到" childData" ...另外 如何分配" childData"到下一个表格查看单元格。似乎我没有分配这样抛出异常,我做错了什么?任何一个人都可以修改我的代码以使其工作或为我提供一些链接吗?

0 个答案:

没有答案