2014-03-29 17 views
0

我已经习惯切片tableView.If我点击的tableview它总是indexpath 0传递给详细信息视图controller.If的正确indexpath我点击第二排,但它indexpath通过总是传递0不顺着接下去连续传球总是节0

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
    if ([segue.identifier isEqualToString:@"toNext"]) { 
    detailTableViewController *detailVC = [segue destinationViewController]; 
    [detailVC setkMessageDict:(NSDictionary*)[nArray objectAtIndex:[self.mytableView indexPathForSelectedRow].section]]; 
} 

代码有什么问题?

+0

有几个部分?也许你的意思是排不节。 – KudoCC

+0

我有4段..总是返回0. @KudoCC –

+0

@gagarwal你可以提供一些例子吗? –

回答

0
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
    if ([segue.identifier isEqualToString:@"toNext"]) { 
    NSIndexPath *selectedIndex= [self.mytableView indexPathForSelectedRow]; 
    NSDictionary *myDic=(NSDictionary*)[nArray objectAtIndex:indexpath.section]; 
    detailTableViewController *detailVC = [segue destinationViewController]; 
    [detailVC setkMessageDict:(NSDictionary*)[[myDic objectForKey:@"locations"] objectAtIndex:selectedIndex.row]]; 
} 

请检查其从部分实现代码如下正确的数据的阵列,否则NSDictionary值将它添加到阵列,并传递给detailTableViewController然后try.Problem是你不通过部分的indexpath here.Hope其有益您。

+0

仍然相同。你可以给更多的样本 –

+0

请加我skype..Got it我的id? –

+0

明白了..删除 – moosa0709

0
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString * currentRow = [NSString stringWithFormat:@"%ld",(long)indexPath.row]; // Declare this row variable in .h file 
    NSString * currentSection = [NSString stringWithFormat:@"%ld",(long)indexPath.section]; // Declare this section variable in .h file 
} 

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
    if ([segue.identifier isEqualToString:@"toNext"]) { 
    detailTableViewController *detailVC = [segue destinationViewController];  
    detailVC.PassRow = currentRow; 
    detailVC.PassSection = currentSection; 
} 
+0

如果我改变行,它只传递每个部分的所有第一行。 @Ramdy –

+0

PassRow和PassSection是什么样的属性? @Ramdy –

+0

我必须在detailView中声明一个字符串? –

0

尝试使用API​​更新所选行indexPath:

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath 
2

您需要在您的塞克创建指数路径对象:下面的UITableViewDelegate API中

selectRowAtIndexPath:animated:scrollPosition: 

如: -

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

    [self performSegueWithIdentifier:@"toNext" sender:indexPath]; 
} 
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 

    NSIndexPath *indexPath = [self.tableview indexPathForSelectedRow]; 
    NSLog(@" indexPath row %d",indexPath.row); 
    NSLog(@" indexPath row %d",indexPath.section); 
    detailTableViewController *detailVC = [segue destinationViewController]; 
    [detailVC setJobDetailDict:(NSDictionary*)[nArray objectAtIndex:indexPath.row]; 


} 
1

是Ramdy,是对的你需要提到行而不是部分。
使用此....

[detailVC setJobDetailDict:(NSDictionary*)[nArray objectAtIndex:[self.mytableView indexPathForSelectedRow].row]]; 
0

最接近答案的问题是尼廷Gohel。但是如果您已将UITableViewCell连接到中的情节提要,他的方法也是错误。

在这种情况下,prepareForSegue方法提供了正确的UITableViewCell作为存储在参数sender中的参数。这完全由UITableView处理。所以,正确的代码是:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if ([sender isKindOfClass:[UITableViewCell class]] && [segue.identifier isEqualToString:@"toNext"]) 
    { 
     NSIndexPath *indexPath = [self.mytableView indexPathForCell:sender]; 

     detailTableViewController *detailVC = [segue destinationViewController]; 
     [detailVC setJobDetailDict:(NSDictionary*)[nArray objectAtIndex:indexPath.row]; 
    } 
} 

不要忘记检查其是否SEGUE名。

+0

感谢您的answer.still相同的问题始终传递每个部分的第一个单元格行值 –