---
title: "Getting indexpath in prepareForSegue"  
description: "Getting indexpath in prepareForSegue"  
author: "Mark Devid"  
published: 2014-10-18  
updated: 2014-10-18  
canonical: https://www.mindstick.com/forum/2414/getting-indexpath-in-prepareforsegue  
category: "iphone"  
tags: ["iphone", "ios"]  
reading_time: 1 minute  

---

# Getting indexpath in prepareForSegue

```
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender     {    if ([segue.identifier isEqualToString:@"Action"])    {        NSIndexPath *indexPath = [self.tbl indexPathForSelectedRow];        SecondViewController *destViewController = segue.destinationViewController;        destViewController.getString = [getArray objectAtIndex:indexPath.row];    }}
```

i wanna to [access](https://www.mindstick.com/articles/12994/how-foreigners-can-access-blocked-websites-in-china) the selected [row](https://www.mindstick.com/forum/1212/this-row-already-belongs-to-this-table) [index](https://www.mindstick.com/blog/198/index-in-sql-server),but show [null](https://www.mindstick.com/forum/33922/how-to-use-null-coalescing-operator-in-c-sharp) for every selected row. please help me?

## Replies

### Reply by Royce Roy

Two cases:\
1)Segue connected from the viewController\

```
Call segue from your didSelectRowAtIndexPath method, pass indexPath as sender-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{    [self performSegueWithIdentifier:@"Action" sender:indexPath];}Then you can get indexPath as sender in prepareForSegue:sender: method- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender  {     if ([segue.identifier isEqualToString:@"Action"])      {           NSIndexPath *indexPath = (NSIndexPath *)sender;           SecondViewController *destViewController = segue.destinationViewController;           destViewController.getString = [getArray objectAtIndex:indexPath.row];      }  }
```

2)segue connected from the cell\
No need to implement didSelectRowAtIndexPath method and performSegueWithIdentifier:.You can directly get sender as UITableviewCell in prepareForSegue:sender: method.\

```
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {    if ([segue.identifier isEqualToString:@"Action"])    {        NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];        SecondViewController *destViewController = segue.destinationViewController;        destViewController.getString = [getArray objectAtIndex:indexPath.row];    }}
```


---

Original Source: https://www.mindstick.com/forum/2414/getting-indexpath-in-prepareforsegue

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
