ios - Segue 始终不传递行的正确索引路径第 0 节

标签 ios objective-c uitableview ios7 uistoryboardsegue

我使用的是分段 tableView。如果我单击 tableview,它总是将索引路径 0 传递给详细 View Controller 。如果我单击第二行,但它的 indexpath pass 总是传递 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]];
}

代码有什么问题?

最佳答案

您需要在序列中创建 index-path 对象,例如:-

-(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];


}

关于ios - Segue 始终不传递行的正确索引路径第 0 节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22727068/

相关文章:

objective-c - 如何链接动态库 Xcode 5

ios - 使用 twitterkit 将图片发布到 Twitter

iphone - UITableViewCell 在排队时是否持有它的 View ? (用于 dequeueReusableCellWithIdentifier)

iphone - 哪个应用程序图标会显示在设备上的 App Store 中?

ios id 不转换为 nsinteger

iphone - UITableView 上显示的多个附件复选标记

ios - 未调用 TableView didSelectRowAtIndexPath

iphone - 如何将 AVAsset 旋转到纵向模式?

android - 适用于 iOS 和 Android 的 AES GCM 加密库

ios - iOS4+中的AES128编码