Storyboard Segue From View Controller to Itself
Solution 1
I developed a method to create a segue using a phantom button. I believe it will solve your problem. You can read about it in my answer here.
Solution 2
If you are using a navigation controller you need to push the ViewController into the nav stack. In this example, i named my ViewController "VDI" in my Storyboard ID setting.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
YourVC *dest = [storyboard instantiateViewControllerWithIdentifier:@"VDI"];
[self.navigationController pushViewController:dest animated:YES];
If you don't want the NavigationController to keep adding itself into your "Back" history you can pop the stack before adding to it like so.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
YourVC *dest = [storyboard instantiateViewControllerWithIdentifier:@"VDI"];
UINavigationController *navController = self.navigationController;
[navController popViewControllerAnimated:NO];
[navController pushViewController:dest animated:YES];
Solution 3
Using Xcode 5 there is a much simpler solution.
- Click the table cell in the storyboard
- Open the Connections Inspector (right arrow icon in the upper right)
- Under "triggered segues" you see "selection"
- Drag from the circle next to "selection" to the cell in the storyboard
That's it.
Solution 4
Instead of performing a segue to the same controller, you can instantiate a view controller (the same one) from storyboard, and then push that onto the navigation controller.
Solution 5
Interface Builder approach: Just segue to a storyboard reference which refers back to the presenting view controller.
Related videos on Youtube
Jorge
Updated on July 05, 2022Comments
-
Jorge almost 2 years
I am trying to make a mechanism to drill down a file / folder list. The idea is to show the same file list view controller every time the user selects a folder, and show a file detail view controller if he/she selects a file.
So far, I have created a segue from the file list view controller to the file detail view controller, and a segue from the file list table view cell to the the file list table view controller:
The issue with this is that as soon as the user taps the cell, the segue is executed. I would like to remove the segue from the table view cell and make one from the file list view controller to itself. That way, I could trigger the right segue programmatically when the user tapped the cell.
So, my question is: Is it possible to create a segue from a view controller to itself in Interface Builder?
-
John Henckel about 10 yearsYes, using xcode 5 you can. see post.
-
DawnSong almost 7 yearsOpen the Editor menu, click
Show Document Outline
, then just right-button-drag from the cell to the Outline's File ListViewController
object.
-
-
Jorge over 12 yearsThis put me on the right track. I added a button on the "Dock", and connected it to the file list view controller. Now I can perform the segue programmatically as I wanted. Thanks!
-
jogloran almost 12 yearsI wish this weren't necessary just to get a self-segue, but this works.
-
strada about 11 yearsMustafa's solution is less hacky and pretty straightforward. Making segues to same views with phantom buttons will only make your storyboard a mess.
-
siburb over 10 yearsBoth this one and @TJ/@Jorge methods will work. I've gone for this way because it feels cleaner. Benefits that I can see in the other method are that you can see your looping segues in the storyboard, and that you can handle all your navigation in "prepareForSegue:"
-
John Smith almost 10 yearsThis approach works like a charm with no line of code.
-
Nerrolken almost 10 yearsWorked perfectly! Also, that's the "Storyboard ID" in XCode that he set to "VDI," for those looking to recreate this.
-
Steve Moser almost 9 yearsI like the phantom button solution better all my forward transitions go through prepareForSegue: instead of remember if a transition is created in IB or code.
-
CupawnTae over 8 yearsThis is the correct answer for xcode 5+ and these days you should use a "show" segue for this.
-
db0 almost 8 yearsDoesn't seem to work for me, the view controller doesn't become "blue" to allow to add the segue.
-
Roland T. over 6 yearsThis approach is the nicest if other navigation is done with segues in IB! Thanks!
-
Christophe Blin over 5 yearsShould definitely be the accepted answer because storyboard reference are now available (which was not the case when op ask the question)
-
ZShock over 5 yearsI found this to be the most elegant solution now that it's available
-
John J. Camilleri over 5 yearsExtra details: you need to give your controller a Storyboard ID and then use that ID in the Referenced ID field of the reference.