Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tatsuro-ueda/3323922 to your computer and use it in GitHub Desktop.
Save tatsuro-ueda/3323922 to your computer and use it in GitHub Desktop.
【テーブル】【セグエ】テーブルセルからセグエで情報を渡しながら別のビューへ遷移する

You can wire from TableViewController to other view.

ss

For example, at first, you can set TableViewCell as below:

ss

When tap the cell, the view with the number of tapped cell.

ss

To send the number of tapped cell to next ViewController, you can use performSegueWithIdentifier:sender: and prepareForSegue:sender as below.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self performSegueWithIdentifier:@"showDetail" 
                              sender:[NSString stringWithFormat:@"%d", indexPath.row + 1]];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    DetailViewController *c = segue.destinationViewController;
    c.string = (NSString *)sender;
}

You can download this project and just run it.

https://github.com/weed/p120809_TableCellToView

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment