2015-05-19 108 views
0

我正在使用prepareForSegue和我的UISplitViewController,我有一个NSMutableDictionary填充UITableView的部分。我所试图做的就是通过我的detailViewController所选部分的方法选择的价值的价值,这是我走到这一步:Objective-C prepareForSegue问题

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 

     if ([[segue identifier] isEqualToString:@"showDetail"]) { 

      NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; 
      NSString *strPOIndex = [self.tableData[indexPath.row] valueForKey:@"Vendor"]; 



      LHContactsDetail *controller = (LHContactsDetail *)[[segue destinationViewController] topViewController]; 

      [controller setDetailItem:strPOIndex]; 
      controller.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem; 
      controller.navigationItem.leftItemsSupplementBackButton = YES; 
     } 

    } 

但这个问题,它返回的编号第一部分的项目。例如,如果我点击第2项第1项,它将返回第1项第1项,如果我点击第3项第2项,它将返回第1项第2项。我希望这是有道理的。这就是我如何填充我的tableview:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; 

    NSString *sectionTitle = [contactSectionTitles objectAtIndex:indexPath.section]; 
    NSArray *sectionContacts = [contactDirectoryFinal objectForKey:sectionTitle]; 
    NSString *contacts = [[sectionContacts objectAtIndex:indexPath.row] valueForKey:@"Vendor_Name"]; 

    cell.textLabel.text = contacts; 

    return cell; 

} 

我怎样才能得到正确的值发送给我的detailController方法?

+0

什么返回完全错误的值? 'indexPath'(来自'[self.tableView indexPathForSelectedRow]')还是'strPOIndex'? – Larme

+0

strPOIndex .... indexPath是正确的,它只是总是在第一部分 – user979331

+0

您使用'tableData',但那是什么?我建议你使用与'tableView:CellForRowAtIndexPath:'('sectionTitle','sectionContact')相同的mecanisme来获得你的价值。 – Larme

回答

1

我想知道为什么您的数据源在cellforrow中有所不同,并为segue做好准备。 如果您以与部分和行相同的方式进行管理。 您需要首先通过indexpath.section从数据源获取数据,然后indexpath.row将其更改为prepareforsegue方法。