2014-03-29 29 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相同的問題始終傳遞每個部分的第一個單元格行值 –