Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Segue Back to Self View Controller

I am currently facing a problem that I wanted to segue back to the same view controller by click on a table view cell. For your information, my table view is generated programatically and each of the cells are using NIB files to control.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath (NSIndexPath *)indexPath
{
    if( indexPath.row == 0 ){
         NSLog(@"Clicked");
    }
}

When I clicked on the cell at position number 0, the log does came out. So now I wanted to segue back to the same view controller instead to the others. From the storyboard, it is impossible for me the drag the segue it is because the view controller is only have a scroll view.

E.g: Inside View Controller A have 5 cells, when I clicked on the first cell, it will segue back to View Controller A and pass data.

Please advise ya if you need to see more of my codes. Thanks viewer!

like image 757
Whatever Kitchen Avatar asked Sep 24 '12 10:09

Whatever Kitchen


Video Answer


1 Answers

If I understand you correctly, you want to select a row in your tableView and have it performSegueWithIdentifier back to this same/current UITableViewController?

To do this:

  1. In storyboard, ctrl+drag from the exposed table view cell to the yellow view controller icon in the black bar below. This creates the segue to self view controller.
  2. Click on the segue, and add an identifier; e.g. "segueToSelf"
  3. In your didSelectRowAtIndexPath method, add the following:

    [self performSegueWithIdentifier:@"segueToSelf" sender:self];

like image 174
randomx Avatar answered Sep 21 '22 12:09

randomx